function encode(command, status, transaction, data = []) { const buffer = Buffer.allocUnsafe(4 + data.length); buffer.writeUInt8(command, 0); buffer.writeUInt8(status, 1); buffer.writeUInt16LE(transaction, 2); if (data.length > 0) { data.copy(buffer, 4); } return buffer; }
Object.keys(fileHeader).forEach(function (filePath) { let meta = fileHeader[filePath] let fileBuffer = new Buffer(meta.size) let readSize = project.copy(fileBuffer, 0, pos + meta.offset, pos + meta.offset + meta.size) if (readSize !== meta.size) throw new Error(`unable to unlock ${filePath}.`) let content if (!meta.stat.isFile) content = null else if (meta.stat.isBinary) content = new Buffer(fileBuffer.toString(), 'hex') else content = decrypt(fileBuffer, key) filesMap.set(path.resolve(process.cwd(), filePath), { stat: formatStat(meta.stat), content }) })