chunked_transfer

Crates.iochunked_transfer
lib.rschunked_transfer
version1.5.0
sourcesrc
created_at2015-05-03 20:49:01.809744
updated_at2023-11-23 04:36:30.183912
descriptionEncoder and decoder for HTTP chunked transfer coding (RFC 7230 § 4.1)
homepage
repositoryhttps://github.com/frewsxcv/rust-chunked-transfer
max_upload_size
id2014
size30,243
Corey Farwell (frewsxcv)

documentation

README

rust-chunked-transfer

Documentation

Encoder and decoder for HTTP chunked transfer coding. For more information about chunked transfer encoding:

Example

Decoding

use chunked_transfer::Decoder;
use std::io::Read;

let encoded = b"3\r\nhel\r\nb\r\nlo world!!!\r\n0\r\n\r\n";
let mut decoded = String::new();

let mut decoder = Decoder::new(encoded as &[u8]);
decoder.read_to_string(&mut decoded);

assert_eq!(decoded, "hello world!!!");

Encoding

use chunked_transfer::Encoder;
use std::io::Write;

let mut decoded = "hello world";
let mut encoded: Vec<u8> = vec![];

{
    let mut encoder = Encoder::with_chunks_size(&mut encoded, 5);
    encoder.write_all(decoded.as_bytes());
}

assert_eq!(encoded, b"5\r\nhello\r\n5\r\n worl\r\n1\r\nd\r\n0\r\n\r\n");

Authors

License

Licensed under either of:

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 102

cargo fmt