Skip to content

Commit bf6d760

Browse files
authored
fix: revert use of buffer.concat on node.js (#75)
4.0.9 had a breaking change - the input type of `concat` stopped accepting plain arrays, requiring an array of `Uint8Array`s.
1 parent 3d5f87d commit bf6d760

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/concat.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { asUint8Array } from './util/as-uint8array.js'
44
/**
55
* Returns a new Uint8Array created by concatenating the passed ArrayLikes
66
*/
7-
export function concat (arrays: Uint8Array[], length?: number): Uint8Array {
8-
if (globalThis.Buffer != null) {
9-
return asUint8Array(globalThis.Buffer.concat(arrays, length))
10-
}
11-
7+
export function concat (arrays: Array<ArrayLike<number>>, length?: number): Uint8Array {
128
if (length == null) {
139
length = arrays.reduce((acc, curr) => acc + curr.length, 0)
1410
}

test/concat.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ describe('Uint8Array concat', () => {
2121
expect(concat([a, b], 8)).to.deep.equal(c)
2222
})
2323

24+
it('concats mixed Uint8Arrays and Arrays', () => {
25+
const a = Uint8Array.from([0, 1, 2, 3])
26+
const b = [4, 5, 6, 7]
27+
const c = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7])
28+
29+
expect(concat([a, b])).to.deep.equal(c)
30+
})
31+
32+
it('concats mixed Uint8Arrays and Arrays with a length', () => {
33+
const a = Uint8Array.from([0, 1, 2, 3])
34+
const b = [4, 5, 6, 7]
35+
const c = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7])
36+
37+
expect(concat([a, b], 8)).to.deep.equal(c)
38+
})
39+
2440
it('concat returns Uint8Array', () => {
2541
const a = Uint8Array.from([0, 1, 2, 3])
2642
const b = alloc(10).fill(1)

0 commit comments

Comments
 (0)