chubakabra 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/node/index.js +10 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chubakabra",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "Browser and Node.js utilities for working with key-addressable byte ranges in large binary files",
6
6
  "exports": {
package/src/node/index.js CHANGED
@@ -70,11 +70,13 @@ export function writeKvr(path, entries, codec)
70
70
  header.writeUInt16LE(keySize, 4)
71
71
  header.writeUInt32LE(entries.length, 6)
72
72
  header.writeBigUInt64LE(0n, 10)
73
- fs.writeSync(fd, header)
73
+
74
+ fs.writeSync(fd, header, 0, HEADER_SIZE, 0)
74
75
 
75
76
  let offset = HEADER_SIZE
76
77
  const index = []
77
78
 
79
+ // DATA
78
80
  for (const e of entries)
79
81
  {
80
82
  index.push({
@@ -82,10 +84,12 @@ export function writeKvr(path, entries, codec)
82
84
  from: offset,
83
85
  to: offset + e.data.length
84
86
  })
87
+
85
88
  fs.writeSync(fd, e.data, 0, e.data.length, offset)
86
89
  offset += e.data.length
87
90
  }
88
91
 
92
+ // INDEX
89
93
  const indexOffset = offset
90
94
 
91
95
  for (const i of index)
@@ -94,11 +98,15 @@ export function writeKvr(path, entries, codec)
94
98
  i.key.copy(b, 0)
95
99
  b.writeBigUInt64LE(BigInt(i.from), keySize)
96
100
  b.writeBigUInt64LE(BigInt(i.to), keySize + 8)
97
- fs.writeSync(fd, b)
101
+
102
+ fs.writeSync(fd, b, 0, b.length, offset)
103
+ offset += b.length
98
104
  }
99
105
 
106
+ // PATCH header
100
107
  header.writeBigUInt64LE(BigInt(indexOffset), 10)
101
108
  fs.writeSync(fd, header, 0, HEADER_SIZE, 0)
109
+
102
110
  fs.closeSync(fd)
103
111
  }
104
112