async_chunked_transfer

Crates.ioasync_chunked_transfer
lib.rsasync_chunked_transfer
version1.4.0
sourcesrc
created_at2021-06-26 21:43:22.581329
updated_at2021-06-26 21:43:22.581329
descriptionAsync encoder and decoder for HTTP chunked transfer coding (RFC 7230 § 4.1)
homepage
repositoryhttps://github.com/icelk/async-chunked-transfer
max_upload_size
id415272
size36,249
Icelk (Icelk)

documentation

README

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

Commit count: 96

cargo fmt