mirror of
https://github.com/servo/servo
synced 2026-04-26 01:25:32 +02:00
In CompressionStream API, the compression algorithms are provided by
`flate2::write::{DeflateEncoder, GzEncoder, ZlibEncoder}` and
`brotli::CompressorWriter`, and the decompression algorithms are
provided by `flate2::write::{DeflateDecoder, GzDecoder, ZlibDecoder}`
and `brotli::DecompressorWriter`.
Although all of them `std::io::Write`, they have subtle difference in
their workflow. For example, `DeflateEncoder`, `GzEncoder` and
`ZlibEncoder` are closed by `fn try_finish(&mut self)` or `fn
finish(self)`, while `brotli::CompressorWriter` must be closed by `fn
into_inner(self)`.
We currently directly call those methods from specification steps. This
patch move those method calls into new structs `CompressionContext` and
`DecompressorContext`, to provide an abstraction layer between
specification steps and underlying logics of compression algorithms from
external libraries. This helps to separate the subtle difference in
compression algorithms away from specification steps.
Testing: Refactoring. Covered by tests in `tests/wpt/tests/compression/`
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>