Add workaround for #114227

This commit is contained in:
Alexandru Dima
2021-01-22 13:55:42 +01:00
parent ed00aebc38
commit 1848d3111f
2 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ export async function sha1Hex(str: string): Promise<string> {
// Prefer to use browser's crypto module
if (globalThis?.crypto?.subtle) {
const hash = await globalThis.crypto.subtle.digest({ name: 'sha-1' }, VSBuffer.fromString(str).buffer);
const hash = await globalThis.crypto.subtle.digest({ name: 'sha-1' }, VSBuffer.fromString(str, { dontUseNodeBuffer: true }).buffer);
return toHexString(hash);
}
+3 -2
View File
@@ -34,8 +34,9 @@ export class VSBuffer {
return new VSBuffer(actual);
}
static fromString(source: string): VSBuffer {
if (hasBuffer) {
static fromString(source: string, options?: { dontUseNodeBuffer?: boolean; }): VSBuffer {
const dontUseNodeBuffer = options?.dontUseNodeBuffer || false;
if (!dontUseNodeBuffer && hasBuffer) {
return new VSBuffer(Buffer.from(source));
} else if (hasTextEncoder) {
if (!textEncoder) {