Skip to content

Get cursor position support #72

@ds-hystax

Description

@ds-hystax

Hi! I'm currently using json-stream to parse a funky file that has a JSON header with binary data afterwards. The library handles such files without issues, but I would like to know the position where JSON ends and data starts.

I've managed to do it using the following code, but it's kinda hacky:

import json_stream
from json_stream.select_tokenizer import rust_tokenizer_or_raise

with open('test.bin', 'rb') as test_file:
    tokenizer = rust_tokenizer_or_raise()(test_file, correct_cursor=True)
    header = json_stream.load(self._file, tokenizer=lambda _: tokenizer)
    # parse header here...
    tokenizer.park_cursor()
    binary_start = test_file.tell() + 1
    print(binary_start)

Having a cleaner and documented way to do it in json-stream would be very nice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions