| Crates.io | ndjson_zst |
| lib.rs | ndjson_zst |
| version | 0.2.0 |
| created_at | 2024-05-15 16:46:52.965691+00 |
| updated_at | 2024-05-16 13:35:32.732065+00 |
| description | simple nsjson zst reader/writer |
| homepage | |
| repository | https://github.com/boojongmin/ndjson_zst |
| max_upload_size | |
| id | 1241256 |
| size | 11,738 |
NdjsonZst is a Rust library for writing and reading newline-delimited JSON (NDJSON) files that are compressed using Zstandard (zstd). This library provides two primary structures: NdjsonZstWriter and NdjsonZstReader, enabling you to efficiently handle NDJSON files with compression.
NdjsonZstWriter to write NDJSON data to a compressed file.NdjsonZstReader to read NDJSON data from a compressed file.NdjsonZstWriter allows writing data while removing newline (\n) and carriage return (\r) characters from the input string.To use NdjsonZst, add the following dependencies to your Cargo.toml:
[dependencies]
ndjson_zst = "0.1.0"
use std::fs::File;
use ndjson_zst::NdjsonZstWriter;
fn main() {
let file_path = "data.zst";
let mut writer = NdjsonZstWriter::from(file_path);
writer.write(r#"{"name": "Alice", "age": 30}"#);
writer.write_with_remove_line("Line with\nnewlines\n");
}
use ndjson_zst::NdjsonZstReader;
fn main() {
let file_path = "data.zst";
let reader = NdjsonZstReader::from(file_path);
for line in reader.lines() {
println!("{}", line);
}
}
NdjsonZstWriterfrom(value: &str) -> SelfCreates a new NdjsonZstWriter instance from a file path.
new(f: File) -> SelfCreates a new NdjsonZstWriter instance from a File.
write(&mut self, data: &str)Writes a string to the NDJSON file, followed by a newline character.
write_with_remove_line(&mut self, data: &str)Writes a string to the NDJSON file after removing all newline (\n) and carriage return (\r) characters, followed by a newline character.
NdjsonZstReaderfrom(value: &str) -> SelfCreates a new NdjsonZstReader instance from a file path.
new(f: File) -> SelfCreates a new NdjsonZstReader instance from a File.
lines(&self) -> std::str::LinesReturns an iterator over the lines of the NDJSON file.
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a pull request or open an issue if you have any suggestions or improvements.
NdjsonZstReader reads the entire file into memory. Future improvements may include supporting streaming reads for handling large files efficiently.This README provides a basic overview and example usage of the NdjsonZst library. For more detailed information, please refer to the source code and inline documentation.