mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-16 04:43:40 +00:00
14 lines
497 B
JavaScript
14 lines
497 B
JavaScript
module.exports = (id, chunkData, hasSubchunks) => {
|
|
if (chunkData.length > 0x7fff) {
|
|
throw new Error('chunkData can not be greater than 32767 bytes');
|
|
}
|
|
|
|
const header = Buffer.alloc(4);
|
|
header.writeUInt16LE(id);
|
|
const chunkLengthBinaryString = chunkData.length.toString(2).padStart(15, '0');
|
|
const secondByteBinary = `${hasSubchunks ? '1' : '0'}${chunkLengthBinaryString}`;
|
|
header.writeUInt16LE(parseInt(secondByteBinary, 2), 2);
|
|
|
|
return Buffer.concat([header, chunkData]);
|
|
};
|