#codec #transfer #chunked #encoder #decoder #rfc #coding

async_chunked_transfer

Async encoder and decoder for HTTP chunked transfer coding (RFC 7230 § 4.1)

1 stable release

1.4.0 Jun 26, 2021

#2874 in Parser implementations

Download history 3/week @ 2024-07-19 9/week @ 2024-07-26 6/week @ 2024-08-02 5/week @ 2024-08-09 5/week @ 2024-08-16 4/week @ 2024-08-23 8/week @ 2024-08-30 3/week @ 2024-09-06 13/week @ 2024-09-13 18/week @ 2024-09-20 19/week @ 2024-09-27 5/week @ 2024-10-04 13/week @ 2024-10-11 20/week @ 2024-10-18 13/week @ 2024-10-25 8/week @ 2024-11-01

54 downloads per month
Used in 2 crates (via kvarn-extensions)

Apache-2.0

25KB
462 lines

async-chunked-transfer

Note: The only difference between this and chunked_transfer is that you MUST call Encoder::finish before dropping the encoder.

Documentation

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

Example

Decoding

use async_chunked_transfer::Decoder;
use tokio::io::AsyncReadExt;

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

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

Encoding

use chunked_transfer::Encoder;
use tokio::io::AsyncWriteExt;

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()).await;
    encoder.finish().await;
}

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

Authors

Dependencies

~2.1–7.5MB
~50K SLoC