mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-22 07:29:13 +00:00
replace NodeJS buffer with Uint8Array
This commit is contained in:
@@ -1,4 +1,14 @@
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (packetHeaderChunk: Buffer, systemNameChunk: Buffer, trackerListChunk: Buffer): Buffer =>
|
||||
chunk(0x6756, Buffer.concat([packetHeaderChunk, systemNameChunk, trackerListChunk]), true);
|
||||
export default (
|
||||
packetHeaderChunk: Uint8Array,
|
||||
systemNameChunk: Uint8Array,
|
||||
trackerListChunk: Uint8Array
|
||||
): Uint8Array => {
|
||||
const chunkData = new Uint8Array(packetHeaderChunk.length + systemNameChunk.length + trackerListChunk.length);
|
||||
|
||||
chunkData.set(packetHeaderChunk);
|
||||
chunkData.set(systemNameChunk, packetHeaderChunk.length);
|
||||
chunkData.set(trackerListChunk, packetHeaderChunk.length + systemNameChunk.length);
|
||||
return chunk(0x6756, chunkData, true);
|
||||
};
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (systemName: string): Buffer => chunk(0x0001, Buffer.from(systemName), false);
|
||||
export default (systemName: string): Uint8Array => chunk(0x0001, new TextEncoder().encode(systemName), false);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (trackerId: number, trackerNameChunk: Buffer): Buffer => chunk(trackerId, trackerNameChunk, true);
|
||||
export default (trackerId: number, trackerNameChunk: Uint8Array): Uint8Array =>
|
||||
chunk(trackerId, trackerNameChunk, true);
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (trackerChunks: Buffer[]): Buffer => chunk(0x0002, Buffer.concat(trackerChunks), true);
|
||||
export default (trackerChunks: Uint8Array[]): Uint8Array => {
|
||||
let trackerChunksTotalLength = 0;
|
||||
|
||||
trackerChunks.forEach((trackerChunk) => {
|
||||
trackerChunksTotalLength += trackerChunk.length;
|
||||
});
|
||||
|
||||
const trackerChunksBytes = new Uint8Array(trackerChunksTotalLength);
|
||||
|
||||
let offset = 0;
|
||||
|
||||
trackerChunks.forEach((trackerChunk) => {
|
||||
trackerChunksBytes.set(trackerChunk, offset);
|
||||
offset += trackerChunk.length;
|
||||
});
|
||||
return chunk(0x0002, trackerChunksBytes, true);
|
||||
};
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import chunk from '../chunk';
|
||||
|
||||
export default (trackerName: string) => chunk(0x0000, Buffer.from(trackerName), false);
|
||||
export default (trackerName: string) => chunk(0x0000, new TextEncoder().encode(trackerName), false);
|
||||
|
||||
Reference in New Issue
Block a user