diff --git a/src/orjsonl/__init__.py b/src/orjsonl/__init__.py index 3c48b9f..a55093c 100644 --- a/src/orjsonl/__init__.py +++ b/src/orjsonl/__init__.py @@ -7,3 +7,33 @@ append, extend, ) +from orjson import ( + OPT_NAIVE_UTC, + OPT_NON_STR_KEYS, + OPT_OMIT_MICROSECONDS, + OPT_PASSTHROUGH_DATACLASS, + OPT_PASSTHROUGH_DATETIME, + OPT_PASSTHROUGH_SUBCLASS, + OPT_SERIALIZE_NUMPY, + OPT_SORT_KEYS, + OPT_STRICT_INTEGER, + OPT_UTC_Z, +) + +__all__ = ( + stream, + load, + save, + append, + extend, + OPT_NAIVE_UTC, + OPT_NON_STR_KEYS, + OPT_OMIT_MICROSECONDS, + OPT_PASSTHROUGH_DATACLASS, + OPT_PASSTHROUGH_DATETIME, + OPT_PASSTHROUGH_SUBCLASS, + OPT_SERIALIZE_NUMPY, + OPT_SORT_KEYS, + OPT_STRICT_INTEGER, + OPT_UTC_Z, +) diff --git a/src/orjsonl/orjsonl.py b/src/orjsonl/orjsonl.py index 97ab890..6478e91 100644 --- a/src/orjsonl/orjsonl.py +++ b/src/orjsonl/orjsonl.py @@ -71,10 +71,11 @@ def save( compression_threads (int, optional): An optional integer passed to xopen.xopen() as the 'threads' argument that specifies the number of threads that should be used for compression. Defaults to None. compression_format (str, optional): An optional string passed to xopen.xopen() as the 'format' argument that overrides the autodetection of the file's compression format based on its extension. Possible values are 'gz', 'xz', 'bz2' and 'zst'. Defaults to None.""" + option &= ~orjson.OPT_INDENT_2 + option |= orjson.OPT_APPEND_NEWLINE with xopen(path, 'wb', compresslevel=compression_level, threads=compression_threads, format=compression_format) as writer: for item in data: writer.write(orjson.dumps(item, default=default, option=option)) - writer.write(b'\n') def append( @@ -99,12 +100,13 @@ def append( compression_threads (int, optional): An optional integer passed to xopen.xopen() as the 'threads' argument that specifies the number of threads that should be used for compression. Defaults to None. compression_format (str, optional): An optional string passed to xopen.xopen() as the 'format' argument that overrides the autodetection of the file's compression format based on its extension or content. Possible values are 'gz', 'xz', 'bz2' and 'zst'. Defaults to None.""" + option &= ~orjson.OPT_INDENT_2 + option |= orjson.OPT_APPEND_NEWLINE with xopen(path, 'ab', compresslevel=compression_level, threads=compression_threads, format=compression_format) as writer: if not newline: writer.write(b'\n') writer.write(orjson.dumps(data, default=default, option=option)) - writer.write(b'\n') def extend( @@ -129,10 +131,11 @@ def extend( compression_threads (int, optional): An optional integer passed to xopen.xopen() as the 'threads' argument that specifies the number of threads that should be used for compression. Defaults to None. compression_format (str, optional): An optional string passed to xopen.xopen() as the 'format' argument that overrides the autodetection of the file's compression format based on its extension or content. Possible values are 'gz', 'xz', 'bz2' and 'zst'. Defaults to None.""" + option &= ~orjson.OPT_INDENT_2 + option |= orjson.OPT_APPEND_NEWLINE with xopen(path, 'ab', compresslevel=compression_level, threads=compression_threads, format=compression_format) as writer: if not newline: writer.write(b'\n') for item in data: writer.write(orjson.dumps(item, default=default, option=option)) - writer.write(b'\n')