(packFile: NewPackedFile)
| 2281 | return result; |
| 2282 | }; |
| 2283 | export const serializePackFileDataToBuffer = (packFile: NewPackedFile): Buffer => { |
| 2284 | if (packFile.buffer) { |
| 2285 | return packFile.buffer; |
| 2286 | } |
| 2287 | if (!packFile.schemaFields || !packFile.tableSchema) { |
| 2288 | throw new Error(`Cannot serialize pack file "${packFile.name}" without buffer or schema data`); |
| 2289 | } |
| 2290 | const buffers: Buffer[] = []; |
| 2291 | if (packFile.name.endsWith(".loc")) { |
| 2292 | buffers.push(Buffer.from([0xff, 0xfe])); |
| 2293 | buffers.push(Buffer.from([0x4c, 0x4f, 0x43])); |
| 2294 | buffers.push(Buffer.from([0x00])); |
| 2295 | const rowCountBuffer = Buffer.allocUnsafe(4); |
| 2296 | rowCountBuffer.writeInt32LE(1, 0); |
| 2297 | buffers.push(rowCountBuffer); |
| 2298 | } else { |
| 2299 | if (packFile.version != null) { |
| 2300 | const versionBuffer = Buffer.allocUnsafe(4); |
| 2301 | versionBuffer.writeInt32LE(packFile.version, 0); |
| 2302 | buffers.push(Buffer.from([0xfc, 0xfd, 0xfe, 0xff])); |
| 2303 | buffers.push(versionBuffer); |
| 2304 | } |
| 2305 | buffers.push(Buffer.from([0x01])); |
| 2306 | } |
| 2307 | const rowCount = packFile.schemaFields.length / packFile.tableSchema.fields.length; |
| 2308 | const rowCountBuffer = Buffer.allocUnsafe(4); |
| 2309 | rowCountBuffer.writeInt32LE(rowCount, 0); |
| 2310 | buffers.push(rowCountBuffer); |
| 2311 | for (const schemaField of packFile.schemaFields) { |
| 2312 | buffers.push(serializeSchemaFieldToBuffer(schemaField)); |
| 2313 | } |
| 2314 | return Buffer.concat(buffers); |
| 2315 | }; |
| 2316 | const ensurePackFileReadyForWrite = (packFile: NewPackedFile): NewPackedFile => { |
| 2317 | if (packFile.buffer) { |
| 2318 | if (packFile.file_size == null) { |
no test coverage detected