Skip to content

Commit d4b7b67

Browse files
committed
feat: Uint8Array<SharedArrayBuffer> is accepted in multi-byte decode
1 parent de80bb3 commit d4b7b67

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

multi-byte.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import type { Uint8ArrayBuffer } from './array.js';
3636
export function createMultibyteDecoder(
3737
encoding: string,
3838
loose?: boolean
39-
): (arr: Uint8ArrayBuffer, stream?: boolean) => string;
39+
): (arr: Uint8Array, stream?: boolean) => string;
4040

4141
/**
4242
* Create an encoder for a supported legacy multi-byte `encoding`, given its lowercased name `encoding`.

tests/multi-byte.encode.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import { test, describe } from 'node:test'
33
import { readFileSync } from 'node:fs'
44
import { join } from 'node:path'
55

6+
const SharedArrayBuffer = globalThis.SharedArrayBuffer ?? ArrayBuffer
7+
const toShared = (u8) => {
8+
const res = new Uint8Array(new SharedArrayBuffer(u8.length))
9+
res.set(u8)
10+
return res
11+
}
12+
613
describe('multi-byte encodings are supersets of ascii', () => {
714
// Except iso-2022-jp
815
for (const encoding of ['big5', 'euc-kr', 'euc-jp', 'shift_jis', 'gbk', 'gb18030']) {
@@ -19,7 +26,7 @@ describe('multi-byte encodings are supersets of ascii', () => {
1926

2027
t.assert.strictEqual(str.length, 1, i)
2128
t.assert.strictEqual(str.codePointAt(0), i, i)
22-
29+
t.assert.strictEqual(decoder(toShared(Uint8Array.of(i))), str)
2330
t.assert.deepStrictEqual(encoder(str), Uint8Array.of(i))
2431
}
2532
})
@@ -222,6 +229,7 @@ describe('roundtrip, tables', () => {
222229
}
223230

224231
t.assert.doesNotThrow(() => t.assert.strictEqual(dec(enc(str)), str), description)
232+
t.assert.doesNotThrow(() => t.assert.strictEqual(dec(toShared(enc(str))), str), description)
225233
}
226234
})
227235
}

0 commit comments

Comments
 (0)