rida-format 2.0.2__tar.gz → 3.0.2__tar.gz

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 (31) hide show
  1. {rida_format-2.0.2 → rida_format-3.0.2}/CHANGELOG.md +5 -0
  2. {rida_format-2.0.2/src/rida_format.egg-info → rida_format-3.0.2}/PKG-INFO +4 -4
  3. {rida_format-2.0.2 → rida_format-3.0.2}/RIDA-FORMAT.md +7 -2
  4. {rida_format-2.0.2 → rida_format-3.0.2}/RIDA-README.md +3 -3
  5. {rida_format-2.0.2 → rida_format-3.0.2}/pyproject.toml +1 -1
  6. {rida_format-2.0.2 → rida_format-3.0.2}/src/rida/__init__.py +60 -14
  7. {rida_format-2.0.2 → rida_format-3.0.2/src/rida_format.egg-info}/PKG-INFO +4 -4
  8. {rida_format-2.0.2 → rida_format-3.0.2}/tests/test_rida.py +23 -0
  9. {rida_format-2.0.2 → rida_format-3.0.2}/LICENSE +0 -0
  10. {rida_format-2.0.2 → rida_format-3.0.2}/MANIFEST.in +0 -0
  11. {rida_format-2.0.2 → rida_format-3.0.2}/docs/rida-metadata.html +0 -0
  12. {rida_format-2.0.2 → rida_format-3.0.2}/setup.cfg +0 -0
  13. {rida_format-2.0.2 → rida_format-3.0.2}/src/rida/__main__.py +0 -0
  14. {rida_format-2.0.2 → rida_format-3.0.2}/src/rida/_encryption.py +0 -0
  15. {rida_format-2.0.2 → rida_format-3.0.2}/src/rida_format.egg-info/SOURCES.txt +0 -0
  16. {rida_format-2.0.2 → rida_format-3.0.2}/src/rida_format.egg-info/dependency_links.txt +0 -0
  17. {rida_format-2.0.2 → rida_format-3.0.2}/src/rida_format.egg-info/entry_points.txt +0 -0
  18. {rida_format-2.0.2 → rida_format-3.0.2}/src/rida_format.egg-info/requires.txt +0 -0
  19. {rida_format-2.0.2 → rida_format-3.0.2}/src/rida_format.egg-info/top_level.txt +0 -0
  20. {rida_format-2.0.2 → rida_format-3.0.2}/tests/fixture_spec.py +0 -0
  21. {rida_format-2.0.2 → rida_format-3.0.2}/tests/fixtures/golden-source-dictionary.json +0 -0
  22. {rida_format-2.0.2 → rida_format-3.0.2}/tests/fixtures/golden-source-sequential.json +0 -0
  23. {rida_format-2.0.2 → rida_format-3.0.2}/tests/fixtures/golden-v1-dictionary-denseData.rida +0 -0
  24. {rida_format-2.0.2 → rida_format-3.0.2}/tests/fixtures/golden-v1-dictionary-denseIndex.rida +0 -0
  25. {rida_format-2.0.2 → rida_format-3.0.2}/tests/fixtures/golden-v1-dictionary-sparseData.rida +0 -0
  26. {rida_format-2.0.2 → rida_format-3.0.2}/tests/fixtures/golden-v1-dictionary-sparseIndex.rida +0 -0
  27. {rida_format-2.0.2 → rida_format-3.0.2}/tests/fixtures/golden-v1-sequential-denseData.rida +0 -0
  28. {rida_format-2.0.2 → rida_format-3.0.2}/tests/fixtures/golden-v1-sequential-denseIndex.rida +0 -0
  29. {rida_format-2.0.2 → rida_format-3.0.2}/tests/fixtures/golden-v1-sequential-sparseData.rida +0 -0
  30. {rida_format-2.0.2 → rida_format-3.0.2}/tests/fixtures/golden-v1-sequential-sparseIndex.rida +0 -0
  31. {rida_format-2.0.2 → rida_format-3.0.2}/tests/make_fixtures.py +0 -0
@@ -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.2 — Encryption included in the default install
4
9
 
5
10
  - Made cryptography a required dependency so pip install rida-format includes encryption support.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rida-format
3
- Version: 2.0.2
3
+ Version: 3.0.2
4
4
  Summary: Range Indexed Data Access (RIDA) static data format and library
5
5
  Author: Syed Ali Hamza Chishty
6
6
  Maintainer-email: Qasra Foundation <admin@qasra.org>
@@ -22,7 +22,7 @@ License-File: LICENSE
22
22
  Requires-Dist: cryptography>=42.0
23
23
  Dynamic: license-file
24
24
 
25
- # RIDA Python library — 2.0.2
25
+ # RIDA Python library — 3.0.2
26
26
 
27
27
  RIDA means **Range Indexed Data Access**. It is an installable Python library
28
28
  and terminal tool that builds a RIDA dataset from a collection of JSON records.
@@ -471,7 +471,7 @@ rida verify UsersData.rida
471
471
 
472
472
  ## Where RIDA can read data
473
473
 
474
- RIDA 2.0.2 can read a data file from the local computer or from a direct
474
+ RIDA 3.0.2 can read a data file from the local computer or from a direct
475
475
  HTTP/HTTPS file URL. For remote reads, RIDA sends ordinary HTTP byte-range
476
476
  requests; it does not use a cloud-provider SDK. This makes it compatible with
477
477
  object storage that returns the requested bytes as HTTP `206 Partial Content`
@@ -981,7 +981,7 @@ The filenames are source names, not guaranteed numbered record IDs. The map desc
981
981
 
982
982
  ## Current scope
983
983
 
984
- RIDA 2.0.2 implements primary lookup — `record ID + field name → value` — plus
984
+ RIDA 3.0.2 implements primary lookup — `record ID + field name → value` — plus
985
985
  multi-field reads (`get_many`, `get_record`), numbered folder IDs with a map that
986
986
  turns a name into one, a data-file integrity check, and optional AES-256-GCM
987
987
  encryption of every stored value. Optional exact-match,
@@ -103,7 +103,7 @@ The index is a fixed 72-byte header followed by one LZMA-compressed catalog.
103
103
 
104
104
  ### 2.1 Index header
105
105
 
106
- `struct` format `>8sIIIIIQI32s`:
106
+ `struct` format `>8sIIIIQII32s`:
107
107
 
108
108
  | Offset | Size | Field | Meaning |
109
109
  | --- | --- | --- | --- |
@@ -117,6 +117,11 @@ The index is a fixed 72-byte header followed by one LZMA-compressed catalog.
117
117
  | 36 | 4 | `flags` | bit 0 set means the values are encrypted |
118
118
  | 40 | 32 | `data_digest` | SHA-256 of the whole data region, all zeros when not computed |
119
119
 
120
+ Older Python writers put a 32-bit data length at offset 24, followed by a
121
+ 64-bit codec code. Readers accept that layout too. When the low word of the
122
+ length is zero, the catalog's final data offset distinguishes a legacy length
123
+ from a genuine multiple of 4 GiB.
124
+
120
125
  A reader checks `data_length` against the size of the data file before serving
121
126
  anything, so a truncated or mismatched download fails immediately rather than
122
127
  part-way through a lookup.
@@ -247,4 +252,4 @@ why `shamela/Bukhari/5` resolves to `1/1/1/5` without the caller naming it.
247
252
  decompression, catches damage before any JSON is parsed.
248
253
  * **No header to keep in step.** The data file has nothing to get out of date.
249
254
  * **Changing the field set is a rebuild.** The schema is fixed for the life of a
250
- dataset; that is what lets a lookup be a single range.
255
+ dataset; that is what lets a lookup be a single range.
@@ -1,4 +1,4 @@
1
- # RIDA Python library — 2.0.2
1
+ # RIDA Python library — 3.0.2
2
2
 
3
3
  RIDA means **Range Indexed Data Access**. It is an installable Python library
4
4
  and terminal tool that builds a RIDA dataset from a collection of JSON records.
@@ -447,7 +447,7 @@ rida verify UsersData.rida
447
447
 
448
448
  ## Where RIDA can read data
449
449
 
450
- RIDA 2.0.2 can read a data file from the local computer or from a direct
450
+ RIDA 3.0.2 can read a data file from the local computer or from a direct
451
451
  HTTP/HTTPS file URL. For remote reads, RIDA sends ordinary HTTP byte-range
452
452
  requests; it does not use a cloud-provider SDK. This makes it compatible with
453
453
  object storage that returns the requested bytes as HTTP `206 Partial Content`
@@ -957,7 +957,7 @@ The filenames are source names, not guaranteed numbered record IDs. The map desc
957
957
 
958
958
  ## Current scope
959
959
 
960
- RIDA 2.0.2 implements primary lookup — `record ID + field name → value` — plus
960
+ RIDA 3.0.2 implements primary lookup — `record ID + field name → value` — plus
961
961
  multi-field reads (`get_many`, `get_record`), numbered folder IDs with a map that
962
962
  turns a name into one, a data-file integrity check, and optional AES-256-GCM
963
963
  encryption of every stored value. Optional exact-match,
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rida-format"
7
- version = "2.0.2"
7
+ version = "3.0.2"
8
8
  description = "Range Indexed Data Access (RIDA) static data format and library"
9
9
  readme = "RIDA-README.md"
10
10
  requires-python = ">=3.10"
@@ -35,6 +35,7 @@ import http.client
35
35
  import json
36
36
  import lzma
37
37
  import os
38
+ import re
38
39
  import select
39
40
  import struct
40
41
  import sys
@@ -44,7 +45,7 @@ import time
44
45
  import urllib.error
45
46
  import urllib.parse
46
47
  import urllib.request
47
- from dataclasses import dataclass, field
48
+ from dataclasses import dataclass, field, replace
48
49
  from pathlib import Path
49
50
  from typing import Any, BinaryIO, Callable, Iterable, Iterator
50
51
 
@@ -77,7 +78,7 @@ INDEX_MAGIC = b"RIDAIDX1"
77
78
  INDEX_VERSION = 1
78
79
  #: magic, index version, catalog length, raw catalog length, record count,
79
80
  #: data length, value codec code, flags, data digest.
80
- INDEX_HEADER = struct.Struct(">8sIIIIIQI32s")
81
+ INDEX_HEADER = struct.Struct(">8sIIIIQII32s")
81
82
  INDEX_FLAG_ENCRYPTED = 0x01
82
83
  _INDEX_SIZE = INDEX_HEADER.size
83
84
  _CODEC_CODES = {VALUE_CODEC_DEFLATE: 1, VALUE_CODEC_PLAIN: 2}
@@ -88,7 +89,7 @@ CATALOG_HEADER = struct.Struct(">8sIIQIIIQ")
88
89
  MODE_DENSE = 1
89
90
  MODE_SPARSE = 2
90
91
  _READ_BLOCK = 1024 * 1024
91
- __version__ = "2.0.2"
92
+ __version__ = "3.0.2"
92
93
  ProgressCallback = Callable[[str, int, int], None]
93
94
 
94
95
 
@@ -2589,7 +2590,7 @@ def _pack_index_bytes(
2589
2590
  )
2590
2591
 
2591
2592
 
2592
- def _parse_index(raw: bytes) -> tuple[Index, bytes]:
2593
+ def _unpack_index(raw: bytes) -> tuple[Index, bytes]:
2593
2594
  """Parse an index entry and return ``(Index, compressed_catalog)``."""
2594
2595
  if len(raw) < _INDEX_SIZE:
2595
2596
  raise RidaError("RIDA index is incomplete")
@@ -2628,6 +2629,34 @@ def _parse_index(raw: bytes) -> tuple[Index, bytes]:
2628
2629
  return index, catalog
2629
2630
 
2630
2631
 
2632
+ def _resolve_index_length(index: Index, catalog: Catalog) -> Index:
2633
+ # Older Python files stored the 32-bit length in the high word of the
2634
+ # 64-bit length field. A genuine multiple of 4 GiB has the same encoding,
2635
+ # so use the end of the final catalog row to distinguish the two cases.
2636
+ length = index.data_length
2637
+ if not length or length & 0xFFFFFFFF:
2638
+ return index
2639
+ catalog_end = catalog._data_end()
2640
+ if catalog_end == length:
2641
+ return index
2642
+ if catalog_end == length >> 32:
2643
+ return replace(index, data_length=catalog_end)
2644
+ raise RidaError("RIDA data length does not match its catalog")
2645
+
2646
+
2647
+ def _parse_index(raw: bytes) -> tuple[Index, bytes]:
2648
+ index, compressed = _unpack_index(raw)
2649
+ if index.data_length and not index.data_length & 0xFFFFFFFF:
2650
+ index = _resolve_index_length(index, Catalog(index, compressed))
2651
+ return index, compressed
2652
+
2653
+
2654
+ def _open_index(raw: bytes) -> tuple[Index, Catalog]:
2655
+ index, compressed = _unpack_index(raw)
2656
+ catalog = Catalog(index, compressed)
2657
+ return _resolve_index_length(index, catalog), catalog
2658
+
2659
+
2631
2660
  class Catalog:
2632
2661
  """Decompressed RIDA catalog with record and field location lookups."""
2633
2662
 
@@ -2693,6 +2722,16 @@ class Catalog:
2693
2722
  raw, self.row_offsets_start, self.row_data_start, record_count, row_data_length
2694
2723
  )
2695
2724
 
2725
+ def _data_end(self) -> int:
2726
+ if not self.record_count:
2727
+ return 0
2728
+ start = self.row_data_start + self.row_offsets[-2]
2729
+ end = self.row_data_start + self.row_offsets[-1]
2730
+ offset, _ = _decode_varint(memoryview(self.raw)[start:end], 0)
2731
+ record_id = self.ids[-1] if self.ids else self.record_count
2732
+ pointers = self.pointer_many(record_id, self.fields)
2733
+ return max((start + length for start, length in pointers.values()), default=offset)
2734
+
2696
2735
  def _record_number(self, record_id: str | int) -> int:
2697
2736
  normalized = str(record_id)
2698
2737
  if self.id_to_record is not None:
@@ -3172,14 +3211,13 @@ class RidaFile:
3172
3211
  self.path = Path(path)
3173
3212
  self._key = key
3174
3213
  raw_index = _read_index_file(self.path, index)
3175
- self.index, catalog = _parse_index(raw_index)
3214
+ self.index, self.catalog = _open_index(raw_index)
3176
3215
  if self.index.encrypted and key is None:
3177
3216
  raise RidaError(
3178
3217
  "This RIDA file has an encrypted data region. Pass key= to RidaFile."
3179
3218
  )
3180
3219
  if self.path.stat().st_size != self.index.data_length:
3181
3220
  raise RidaError("RIDA data file does not match its index")
3182
- self.catalog = Catalog(self.index, catalog)
3183
3221
  self.file = self.path.open("rb")
3184
3222
  self.map = self._load_map()
3185
3223
 
@@ -3626,13 +3664,12 @@ class RemoteRidaFile:
3626
3664
  "No local index for this RIDA file. Build the dataset to write one, "
3627
3665
  "or pass index= pointing at it."
3628
3666
  )
3629
- self.index, catalog = _parse_index(raw_index)
3667
+ self.index, self.catalog = _open_index(raw_index)
3630
3668
  if self.index.encrypted and key is None:
3631
3669
  raise RidaError(
3632
3670
  "This RIDA file has an encrypted data region. Pass key= to RemoteRidaFile."
3633
3671
  )
3634
3672
  self.cache_hit = True
3635
- self.catalog = Catalog(self.index, catalog)
3636
3673
 
3637
3674
  @property
3638
3675
  def value_codec(self) -> str:
@@ -3721,11 +3758,11 @@ def open_reader(
3721
3758
  def inspect_metadata(path: Path) -> dict[str, Any]:
3722
3759
  """Describe a dataset from its index and data file. Nothing is fetched."""
3723
3760
  path = Path(path)
3724
- index, catalog = _parse_index(_read_index_file(path))
3725
- catalog_object = Catalog(index, catalog)
3761
+ raw_index = _read_index_file(path)
3762
+ index, catalog_object = _open_index(raw_index)
3726
3763
  return {
3727
3764
  "index": {
3728
- "index_bytes": len(_read_index_file(path)),
3765
+ "index_bytes": len(raw_index),
3729
3766
  "format_version": index.version,
3730
3767
  "value_codec": index.value_codec,
3731
3768
  "catalog_bytes": index.catalog_length,
@@ -3762,9 +3799,9 @@ def verify(
3762
3799
  index: Index | None = None
3763
3800
  encrypted = False
3764
3801
  try:
3765
- index, catalog = _parse_index(_read_index_file(path))
3802
+ index, compressed = _unpack_index(_read_index_file(path))
3766
3803
  encrypted = index.encrypted
3767
- Catalog(index, catalog)
3804
+ index = _resolve_index_length(index, Catalog(index, compressed))
3768
3805
  catalog_ok = True
3769
3806
  except RidaError:
3770
3807
  catalog_ok = False
@@ -4333,7 +4370,16 @@ def _main() -> int:
4333
4370
  cache_parser.add_argument("--url", help="Only act on the cache entry for this URL")
4334
4371
  cache_parser.add_argument("--cache-dir", type=Path)
4335
4372
 
4336
- args = parser.parse_args()
4373
+ argv = sys.argv[1:]
4374
+ for i in range(len(argv) - 1):
4375
+ if argv[i] == "--":
4376
+ break
4377
+ if argv[i] == "--key" and re.fullmatch(r"-[A-Za-z0-9_-]{42}=?", argv[i + 1]):
4378
+ # URL-safe base64 may begin with a dash. Bind it before argparse
4379
+ # can mistake it for another option.
4380
+ argv[i:i + 2] = [f"--key={argv[i + 1]}"]
4381
+ break
4382
+ args = parser.parse_args(argv)
4337
4383
  if args.command == "build" and (getattr(args, "key", None) or getattr(args, "encrypt", False)):
4338
4384
  if not _encryption.is_available():
4339
4385
  print(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rida-format
3
- Version: 2.0.2
3
+ Version: 3.0.2
4
4
  Summary: Range Indexed Data Access (RIDA) static data format and library
5
5
  Author: Syed Ali Hamza Chishty
6
6
  Maintainer-email: Qasra Foundation <admin@qasra.org>
@@ -22,7 +22,7 @@ License-File: LICENSE
22
22
  Requires-Dist: cryptography>=42.0
23
23
  Dynamic: license-file
24
24
 
25
- # RIDA Python library — 2.0.2
25
+ # RIDA Python library — 3.0.2
26
26
 
27
27
  RIDA means **Range Indexed Data Access**. It is an installable Python library
28
28
  and terminal tool that builds a RIDA dataset from a collection of JSON records.
@@ -471,7 +471,7 @@ rida verify UsersData.rida
471
471
 
472
472
  ## Where RIDA can read data
473
473
 
474
- RIDA 2.0.2 can read a data file from the local computer or from a direct
474
+ RIDA 3.0.2 can read a data file from the local computer or from a direct
475
475
  HTTP/HTTPS file URL. For remote reads, RIDA sends ordinary HTTP byte-range
476
476
  requests; it does not use a cloud-provider SDK. This makes it compatible with
477
477
  object storage that returns the requested bytes as HTTP `206 Partial Content`
@@ -981,7 +981,7 @@ The filenames are source names, not guaranteed numbered record IDs. The map desc
981
981
 
982
982
  ## Current scope
983
983
 
984
- RIDA 2.0.2 implements primary lookup — `record ID + field name → value` — plus
984
+ RIDA 3.0.2 implements primary lookup — `record ID + field name → value` — plus
985
985
  multi-field reads (`get_many`, `get_record`), numbered folder IDs with a map that
986
986
  turns a name into one, a data-file integrity check, and optional AES-256-GCM
987
987
  encryption of every stored value. Optional exact-match,
@@ -379,6 +379,19 @@ class GetManyTests(TempDirTestCase):
379
379
 
380
380
 
381
381
  class IntegrityTests(TempDirTestCase):
382
+ def test_reads_legacy_python_index_with_a_final_empty_record(self) -> None:
383
+ target = self.build("legacy.json", {"1": {"v": "hello"}, "2": {}})
384
+ index_path = rida._index_path_for_output(target)
385
+ index_bytes = index_path.read_bytes()
386
+ size = target.stat().st_size
387
+ self.assertEqual(struct.unpack_from(">Q", index_bytes, 24)[0], size)
388
+ index_path.write_bytes(index_bytes[:24] + struct.pack(">II", size, 0) + index_bytes[32:])
389
+
390
+ with rida.open_reader(target) as data:
391
+ self.assertEqual(data.index.data_length, size)
392
+ self.assertEqual(data.get("1", "v"), "hello")
393
+ self.assertTrue(rida.verify(target)["ok"])
394
+
382
395
  def test_verify_detects_a_corrupted_data_region(self) -> None:
383
396
  target = self.build("packed.json", {"1": {"v": "hello"}, "2": {"v": "world"}})
384
397
  raw = bytearray(target.read_bytes())
@@ -1149,6 +1162,16 @@ class EncryptionTests(TempDirTestCase):
1149
1162
  self.assertEqual(result.returncode, 0, result.stderr)
1150
1163
  self.assertIn("Fields: 4", result.stdout)
1151
1164
 
1165
+ def test_cli_accepts_urlsafe_keys_starting_with_two_dashes(self) -> None:
1166
+ key = rida._encryption.encode_key(bytes.fromhex("fbe0") + bytes(30))
1167
+ self.assertTrue(key.startswith("--"))
1168
+ source = _write_json(self.tmp / "dash-key.json", {"1": {"v": "hello"}})
1169
+ target = self.tmp / "DashData.rida"
1170
+ rida.build(source, target, key=key)
1171
+ result = self._run("get", str(target), "1", "v", "--key", key)
1172
+ self.assertEqual(result.returncode, 0, result.stderr)
1173
+ self.assertEqual(result.stdout.strip(), "hello")
1174
+
1152
1175
  def test_cli_remote_get_accepts_a_key(self) -> None:
1153
1176
  target = self._build_encrypted()
1154
1177
  base, _ = self._serve(self.tmp)
File without changes
File without changes
File without changes