Metadata-Version: 2.5
Name: jfiles
Version: 0.1.0
Summary: Read jBASE hashed files (J3, J4, JP and JR) without jBASE
Project-URL: Homepage, https://github.com/jbc-lang/jbcc/tree/main/jfiles
Project-URL: Documentation, https://jbc-lang.org/
Project-URL: Issues, https://github.com/jbc-lang/jbcc/issues
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Database
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# jfiles

jfiles reads jBASE hashed files without jBASE. It understands the four
hashed file types of TAFC: J3, J4, JP and JR. It takes the type from the
first 8 bytes of the file, so one command works for all of them,
dictionaries (`NAME]D`) included.

It needs Python 3.8 or later and nothing else.

```sh
uvx jfiles show FBNK.CUSTOMER          # every record, as a tree
uvx jfiles show FBNK.CUSTOMER 100112   # one record
uvx jfiles keys FBNK.CUSTOMER
uvx jfiles get FBNK.CUSTOMER 100112 > record.bin
uvx jfiles stat FBNK.CUSTOMER
```

| Command | Prints |
| --- | --- |
| `show FILE [KEY ...]` | records as trees of attributes, values and subvalues |
| `keys FILE` | the record keys, one on a line |
| `get FILE KEY` | one record body, as it is stored |
| `dump FILE` | every record: key in hex, length, body in hex |
| `stat FILE` | the file type and its header parameters |

`show` numbers the parts of a record as jBC does, so `3.2.1` is
`REC<3,2,1>`:

```text
MULTI  (17 bytes)
  1: name
  2:
    2.1: a
    2.2:
      2.2.1: b1
      2.2.2: b2
  3: last
```

## From Python

```python
import jfiles

file = jfiles.open('FBNK.CUSTOMER')
for key, body in file.records():
    attributes = body.split(b'\xfe')
print(file.read(b'100112'))
```

Keys and bodies are `bytes`. The marks are 0xfe between attributes, 0xfd
between values and 0xfc between subvalues.

## What it was checked against

The formats were taken from the file drivers of TAFC PB201214 on x86-64
Linux. For each type, files were made by TAFC under scripted writes,
deletes and clears, and jfiles must list each one in the order of TAFC's
`SELECT`. For J4 and JR the same code also writes files, and they are the
same as TAFC's byte for byte.

## Limits

- The command only reads. Do not read a file while jBASE is writing to
  it: jfiles takes no locks.
- Encrypted files and secondary indexes are not handled.
- UD files (a directory with one file for each record) are not hashed
  files and need no tool.

jfiles is part of [jbcc](https://github.com/jbc-lang/jbcc), a jBC to C
compiler. It is released under the
[MIT license](https://github.com/jbc-lang/jbcc/blob/main/jfiles/LICENSE).
