mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-20 14:39:11 +00:00
replace NodeJS buffer with Uint8Array
This commit is contained in:
@@ -1,4 +1,20 @@
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (trackerId: number, fieldChunks: Buffer[]): Buffer =>
|
||||
chunk(trackerId, Buffer.concat(fieldChunks), fieldChunks.length > 0);
|
||||
export default (trackerId: number, fieldChunks: Uint8Array[]): Uint8Array => {
|
||||
let fieldChunksTotalLength = 0;
|
||||
|
||||
fieldChunks.forEach((fieldChunk) => {
|
||||
fieldChunksTotalLength += fieldChunk.length;
|
||||
});
|
||||
|
||||
const fieldChunksBytes = new Uint8Array(fieldChunksTotalLength);
|
||||
|
||||
let offset = 0;
|
||||
|
||||
fieldChunks.forEach((fieldChunk) => {
|
||||
fieldChunksBytes.set(fieldChunk, offset);
|
||||
offset += fieldChunk.length;
|
||||
});
|
||||
|
||||
return chunk(trackerId, fieldChunksBytes, fieldChunks.length > 0);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user