Function ben::encode::jsonl_encode_ben

source ·
pub fn jsonl_encode_ben<R: BufRead, W: Write>(
    reader: R,
    writer: W
) -> Result<()>
Expand description

This function takes a JSONL file and compresses it into the BEN format.

The JSONL file is assumed to be formatted in the standard

{"assignment": [...], "sample": #}

format.

§Arguments

  • reader - A buffered reader for the input file
  • writer - A writer for the output file

§Returns

A Result type that contains the result of the operation

§Example

use std::io::{BufReader, BufWriter};
use serde_json::json;
use ben::encode::jsonl_encode_ben;

let input = r#"{"assignment": [1,1,1,2,2,2], "sample": 1}"#.to_string()
    + "\n"
    + r#"{"assignment": [1,1,2,2,1,2], "sample": 2}"#;

let reader = BufReader::new(input.as_bytes());
let mut write_buffer = Vec::new();
let mut writer = BufWriter::new(&mut write_buffer);

jsonl_encode_ben(reader, writer).unwrap();

println!("{:?}", write_buffer);
// This will output
// [83, 84, 65, 78, 68, 65, 82, 68, 32,
//  66, 69, 78, 32, 70, 73, 76, 69, 2,
//  2, 0, 0, 0, 1, 123, 2, 2, 0, 0, 0,
//  2, 106, 89]