encode_jsonl_to_ben

Function encode_jsonl_to_ben 

Source
pub fn encode_jsonl_to_ben<R: BufRead, W: Write>(
    reader: R,
    writer: W,
    variant: BenVariant,
) -> 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
  • variant - The BEN variant to use (Standard or MkvChain)

§Returns

A Result type that contains the result of the operation

§Example

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

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);

encode_jsonl_to_ben(reader, writer, BenVariant::Standard).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]