rida-format 2.0.1 → 3.0.2
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.
- package/CHANGELOG.md +5 -0
- package/README.md +5 -4
- package/package.json +1 -1
- package/src/cli.js +2 -1
- package/src/index.js +34 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.0.2
|
|
4
|
+
|
|
5
|
+
- Aligned the version numbering for Python, Node.js, and RIDA Studio.
|
|
6
|
+
- Made encrypted and unencrypted datasets readable across all three editions, including existing files written with either index header layout.
|
|
7
|
+
|
|
3
8
|
## 2.0.1 — Encrypted delivery and application examples
|
|
4
9
|
|
|
5
10
|
- Added direct encrypted CDN delivery guidance and server-only key handling.
|
package/README.md
CHANGED
|
@@ -1147,16 +1147,17 @@ it does not change the encoding of the data values.
|
|
|
1147
1147
|
|
|
1148
1148
|
## Format compatibility
|
|
1149
1149
|
|
|
1150
|
-
The Node.js reader and builder
|
|
1150
|
+
The Node.js reader and builder use the same data and index format as Python
|
|
1151
|
+
and RIDA Studio 3.0.2. The reader also accepts the older Python index layout. The
|
|
1151
1152
|
index stores the value codec, encryption flag, data length, SHA-256 digest, and
|
|
1152
1153
|
compressed catalog. The catalog stores field names, record IDs when needed,
|
|
1153
1154
|
record-to-value offsets, and the dense or sparse layout. Values are compact
|
|
1154
1155
|
UTF-8 JSON, optionally raw-Deflate compressed per field, then optionally
|
|
1155
1156
|
encrypted with AES-256-GCM.
|
|
1156
1157
|
|
|
1157
|
-
Reading a dataset does not convert or rewrite it.
|
|
1158
|
-
|
|
1159
|
-
|
|
1158
|
+
Reading a dataset does not convert or rewrite it. Existing encrypted datasets
|
|
1159
|
+
still require their original key. Building a dataset creates new output files
|
|
1160
|
+
from JSON and leaves the source JSON intact.
|
|
1160
1161
|
|
|
1161
1162
|
## Detailed application examples
|
|
1162
1163
|
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -36,7 +36,8 @@ function parseArgs(args) {
|
|
|
36
36
|
if (FLAGS.has(arg)) options[arg] = true;
|
|
37
37
|
else if (VALUE_OPTIONS.has(arg)) {
|
|
38
38
|
const value = args[++i];
|
|
39
|
-
|
|
39
|
+
const dashPrefixedKey = arg === "--key" && /^-[A-Za-z0-9_-]{42}=?$/.test(value ?? "");
|
|
40
|
+
if (!value || (value.startsWith("--") && !dashPrefixedKey)) throw new Error(`Missing value after ${arg}`);
|
|
40
41
|
options[arg.slice(2).replaceAll("-", "")] = value;
|
|
41
42
|
} else if (arg.startsWith("--")) throw new Error(`Unknown option: ${arg}`);
|
|
42
43
|
else positional.push(arg);
|
package/src/index.js
CHANGED
|
@@ -7,10 +7,11 @@ import { inflateRawSync } from "node:zlib";
|
|
|
7
7
|
const require = createRequire(import.meta.url);
|
|
8
8
|
const lzma = require("lzma-native");
|
|
9
9
|
|
|
10
|
-
export const version = "
|
|
10
|
+
export const version = "3.0.2";
|
|
11
11
|
export const MERGE_GAP_LIMIT = 660;
|
|
12
12
|
const INDEX_MAGIC = Buffer.from("RIDAIDX1");
|
|
13
13
|
const CATALOG_MAGIC = Buffer.from("RDACAT01");
|
|
14
|
+
const INDEX_LENGTH_LOW_WORD = 0xFFFFFFFFn;
|
|
14
15
|
|
|
15
16
|
export class RidaError extends Error {
|
|
16
17
|
constructor(message, options) { super(message, options); this.name = "RidaError"; }
|
|
@@ -45,7 +46,6 @@ function parseIndex(raw) {
|
|
|
45
46
|
const recordCount = raw.readUInt32BE(20);
|
|
46
47
|
const dataLengthBig = raw.readBigUInt64BE(24);
|
|
47
48
|
need(versionNo === 1, `Unsupported RIDA index version: ${versionNo}`);
|
|
48
|
-
need(dataLengthBig <= BigInt(Number.MAX_SAFE_INTEGER), "RIDA data file is too large for this Node.js runtime");
|
|
49
49
|
const codecNo = raw.readUInt32BE(32);
|
|
50
50
|
need(codecNo === 1 || codecNo === 2, "RIDA index has an unknown value codec");
|
|
51
51
|
const catalog = raw.subarray(72);
|
|
@@ -55,13 +55,13 @@ function parseIndex(raw) {
|
|
|
55
55
|
version: 3,
|
|
56
56
|
indexVersion: versionNo,
|
|
57
57
|
recordCount,
|
|
58
|
-
dataLength: Number(dataLengthBig),
|
|
59
58
|
valueCodec: codecNo === 1 ? "deflate-per-field" : "plain",
|
|
60
59
|
encrypted: Boolean(raw.readUInt32BE(36) & 1),
|
|
61
60
|
digest: Buffer.from(raw.subarray(40, 72)),
|
|
62
61
|
catalogLength,
|
|
63
62
|
rawCatalogLength,
|
|
64
63
|
},
|
|
64
|
+
dataLengthBig,
|
|
65
65
|
catalog,
|
|
66
66
|
};
|
|
67
67
|
}
|
|
@@ -160,6 +160,28 @@ function locate(catalog, recordId, wantedNames) {
|
|
|
160
160
|
return found;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
function resolveDataLength(length, catalog) {
|
|
164
|
+
// Older Python writers put their length in the high word. A genuine
|
|
165
|
+
// multiple of 4 GiB has the same encoding; the catalog gives the real end.
|
|
166
|
+
if (length && !(length & INDEX_LENGTH_LOW_WORD)) {
|
|
167
|
+
let end = 0;
|
|
168
|
+
if (catalog.recordCount) {
|
|
169
|
+
const recordId = catalog.ids.at(-1) ?? catalog.recordCount;
|
|
170
|
+
const rowStart = catalog.rowDataStart + catalog.rowOffsets.at(-2);
|
|
171
|
+
const rowEnd = catalog.rowDataStart + catalog.rowOffsets.at(-1);
|
|
172
|
+
[end] = readVarint(catalog.raw.subarray(rowStart, rowEnd), 0);
|
|
173
|
+
for (const [offset, size] of locate(catalog, recordId, catalog.fields).values()) {
|
|
174
|
+
end = Math.max(end, offset + size);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const catalogEnd = BigInt(end);
|
|
178
|
+
need(catalogEnd === length || catalogEnd === (length >> 32n), "RIDA data length does not match its catalog");
|
|
179
|
+
length = catalogEnd;
|
|
180
|
+
}
|
|
181
|
+
need(length <= BigInt(Number.MAX_SAFE_INTEGER), "RIDA data file is too large for this Node.js runtime");
|
|
182
|
+
return Number(length);
|
|
183
|
+
}
|
|
184
|
+
|
|
163
185
|
function normalizeKey(key) {
|
|
164
186
|
if (key == null) return null;
|
|
165
187
|
if (Buffer.isBuffer(key) || key instanceof Uint8Array) {
|
|
@@ -230,8 +252,9 @@ export class RidaReader {
|
|
|
230
252
|
else indexLocation = companionPath(String(data), "Index.rida");
|
|
231
253
|
}
|
|
232
254
|
const [indexBytes, mapBytes] = await Promise.all([bytesFrom(indexLocation), map ? bytesFrom(map) : (dataIsUrl ? Promise.resolve(null) : readFile(companionPath(String(data), "Map.json")).catch(() => null))]);
|
|
233
|
-
const { info, catalog: compressed } = parseIndex(indexBytes);
|
|
255
|
+
const { info, dataLengthBig, catalog: compressed } = parseIndex(indexBytes);
|
|
234
256
|
const catalog = await parseCatalog(compressed, info);
|
|
257
|
+
info.dataLength = resolveDataLength(dataLengthBig, catalog);
|
|
235
258
|
const normalizedKey = normalizeKey(key);
|
|
236
259
|
need(!info.encrypted || normalizedKey, "This RIDA file is encrypted; provide its private key");
|
|
237
260
|
let mapping = null;
|
|
@@ -239,8 +262,13 @@ export class RidaReader {
|
|
|
239
262
|
let handle = null;
|
|
240
263
|
if (!dataIsUrl) {
|
|
241
264
|
handle = await open(data instanceof URL ? data : String(data), "r");
|
|
242
|
-
|
|
243
|
-
|
|
265
|
+
try {
|
|
266
|
+
const stat = await handle.stat();
|
|
267
|
+
need(stat.size === info.dataLength, "RIDA data file does not match its index");
|
|
268
|
+
} catch (error) {
|
|
269
|
+
await handle.close();
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
244
272
|
}
|
|
245
273
|
return new RidaReader(data, handle, info, catalog, mapping, normalizedKey);
|
|
246
274
|
}
|