mirror of
https://github.com/denoland/deno.git
synced 2025-01-11 08:33:43 -05:00
feature(web): enable deflate-raw compression format (#14863)
This commit is contained in:
parent
443041c23e
commit
e1d488ab88
3 changed files with 40 additions and 162 deletions
|
@ -16,6 +16,7 @@
|
|||
"CompressionFormat",
|
||||
[
|
||||
"deflate",
|
||||
"deflate-raw",
|
||||
"gzip",
|
||||
],
|
||||
);
|
||||
|
|
|
@ -6,6 +6,8 @@ use deno_core::OpState;
|
|||
use deno_core::Resource;
|
||||
use deno_core::ResourceId;
|
||||
use deno_core::ZeroCopyBuf;
|
||||
use flate2::write::DeflateDecoder;
|
||||
use flate2::write::DeflateEncoder;
|
||||
use flate2::write::GzDecoder;
|
||||
use flate2::write::GzEncoder;
|
||||
use flate2::write::ZlibDecoder;
|
||||
|
@ -19,10 +21,13 @@ use std::rc::Rc;
|
|||
#[derive(Debug)]
|
||||
struct CompressionResource(RefCell<Inner>);
|
||||
|
||||
/// https://wicg.github.io/compression/#supported-formats
|
||||
#[derive(Debug)]
|
||||
enum Inner {
|
||||
DeflateDecoder(ZlibDecoder<Vec<u8>>),
|
||||
DeflateEncoder(ZlibEncoder<Vec<u8>>),
|
||||
DeflateRawDecoder(DeflateDecoder<Vec<u8>>),
|
||||
DeflateRawEncoder(DeflateEncoder<Vec<u8>>),
|
||||
GzDecoder(GzDecoder<Vec<u8>>),
|
||||
GzEncoder(GzEncoder<Vec<u8>>),
|
||||
}
|
||||
|
@ -45,6 +50,10 @@ pub fn op_compression_new(
|
|||
("deflate", false) => {
|
||||
Inner::DeflateEncoder(ZlibEncoder::new(w, Compression::default()))
|
||||
}
|
||||
("deflate-raw", true) => Inner::DeflateRawDecoder(DeflateDecoder::new(w)),
|
||||
("deflate-raw", false) => {
|
||||
Inner::DeflateRawEncoder(DeflateEncoder::new(w, Compression::default()))
|
||||
}
|
||||
("gzip", true) => Inner::GzDecoder(GzDecoder::new(w)),
|
||||
("gzip", false) => {
|
||||
Inner::GzEncoder(GzEncoder::new(w, Compression::default()))
|
||||
|
@ -74,6 +83,16 @@ pub fn op_compression_write(
|
|||
d.flush()?;
|
||||
d.get_mut().drain(..)
|
||||
}
|
||||
Inner::DeflateRawDecoder(d) => {
|
||||
d.write_all(&input)?;
|
||||
d.flush()?;
|
||||
d.get_mut().drain(..)
|
||||
}
|
||||
Inner::DeflateRawEncoder(d) => {
|
||||
d.write_all(&input)?;
|
||||
d.flush()?;
|
||||
d.get_mut().drain(..)
|
||||
}
|
||||
Inner::GzDecoder(d) => {
|
||||
d.write_all(&input)?;
|
||||
d.flush()?;
|
||||
|
@ -100,6 +119,8 @@ pub fn op_compression_finish(
|
|||
let out: Vec<u8> = match inner {
|
||||
Inner::DeflateDecoder(d) => d.finish()?,
|
||||
Inner::DeflateEncoder(d) => d.finish()?,
|
||||
Inner::DeflateRawDecoder(d) => d.finish()?,
|
||||
Inner::DeflateRawEncoder(d) => d.finish()?,
|
||||
Inner::GzDecoder(d) => d.finish()?,
|
||||
Inner::GzEncoder(d) => d.finish()?,
|
||||
};
|
||||
|
|
|
@ -4589,175 +4589,31 @@
|
|||
]
|
||||
},
|
||||
"compression": {
|
||||
"compression-bad-chunks.tentative.any.html": [
|
||||
"chunk of type undefined should error the stream for deflate-raw",
|
||||
"chunk of type null should error the stream for deflate-raw",
|
||||
"chunk of type numeric should error the stream for deflate-raw",
|
||||
"chunk of type object, not BufferSource should error the stream for deflate-raw",
|
||||
"chunk of type array should error the stream for deflate-raw",
|
||||
"chunk of type SharedArrayBuffer should error the stream for deflate-raw",
|
||||
"chunk of type shared Uint8Array should error the stream for deflate-raw"
|
||||
],
|
||||
"compression-bad-chunks.tentative.any.worker.html": [
|
||||
"chunk of type undefined should error the stream for deflate-raw",
|
||||
"chunk of type null should error the stream for deflate-raw",
|
||||
"chunk of type numeric should error the stream for deflate-raw",
|
||||
"chunk of type object, not BufferSource should error the stream for deflate-raw",
|
||||
"chunk of type array should error the stream for deflate-raw",
|
||||
"chunk of type SharedArrayBuffer should error the stream for deflate-raw",
|
||||
"chunk of type shared Uint8Array should error the stream for deflate-raw"
|
||||
],
|
||||
"compression-including-empty-chunk.tentative.any.html": [
|
||||
"the result of compressing [,Hello,Hello] with deflate-raw should be 'HelloHello'",
|
||||
"the result of compressing [Hello,,Hello] with deflate-raw should be 'HelloHello'",
|
||||
"the result of compressing [Hello,Hello,] with deflate-raw should be 'HelloHello'"
|
||||
],
|
||||
"compression-including-empty-chunk.tentative.any.worker.html": [
|
||||
"the result of compressing [,Hello,Hello] with deflate-raw should be 'HelloHello'",
|
||||
"the result of compressing [Hello,,Hello] with deflate-raw should be 'HelloHello'",
|
||||
"the result of compressing [Hello,Hello,] with deflate-raw should be 'HelloHello'"
|
||||
],
|
||||
"compression-multiple-chunks.tentative.any.html": [
|
||||
"compressing 2 chunks with deflate-raw should work",
|
||||
"compressing 3 chunks with deflate-raw should work",
|
||||
"compressing 4 chunks with deflate-raw should work",
|
||||
"compressing 5 chunks with deflate-raw should work",
|
||||
"compressing 6 chunks with deflate-raw should work",
|
||||
"compressing 7 chunks with deflate-raw should work",
|
||||
"compressing 8 chunks with deflate-raw should work",
|
||||
"compressing 9 chunks with deflate-raw should work",
|
||||
"compressing 10 chunks with deflate-raw should work",
|
||||
"compressing 11 chunks with deflate-raw should work",
|
||||
"compressing 12 chunks with deflate-raw should work",
|
||||
"compressing 13 chunks with deflate-raw should work",
|
||||
"compressing 14 chunks with deflate-raw should work",
|
||||
"compressing 15 chunks with deflate-raw should work",
|
||||
"compressing 16 chunks with deflate-raw should work"
|
||||
],
|
||||
"compression-multiple-chunks.tentative.any.worker.html": [
|
||||
"compressing 2 chunks with deflate-raw should work",
|
||||
"compressing 3 chunks with deflate-raw should work",
|
||||
"compressing 4 chunks with deflate-raw should work",
|
||||
"compressing 5 chunks with deflate-raw should work",
|
||||
"compressing 6 chunks with deflate-raw should work",
|
||||
"compressing 7 chunks with deflate-raw should work",
|
||||
"compressing 8 chunks with deflate-raw should work",
|
||||
"compressing 9 chunks with deflate-raw should work",
|
||||
"compressing 10 chunks with deflate-raw should work",
|
||||
"compressing 11 chunks with deflate-raw should work",
|
||||
"compressing 12 chunks with deflate-raw should work",
|
||||
"compressing 13 chunks with deflate-raw should work",
|
||||
"compressing 14 chunks with deflate-raw should work",
|
||||
"compressing 15 chunks with deflate-raw should work",
|
||||
"compressing 16 chunks with deflate-raw should work"
|
||||
],
|
||||
"compression-output-length.tentative.any.html": [
|
||||
"the length of deflated (with -raw) data should be shorter than that of the original data"
|
||||
],
|
||||
"compression-output-length.tentative.any.worker.html": [
|
||||
"the length of deflated (with -raw) data should be shorter than that of the original data"
|
||||
],
|
||||
"compression-bad-chunks.tentative.any.html": true,
|
||||
"compression-bad-chunks.tentative.any.worker.html": true,
|
||||
"compression-including-empty-chunk.tentative.any.html": true,
|
||||
"compression-including-empty-chunk.tentative.any.worker.html": true,
|
||||
"compression-multiple-chunks.tentative.any.html": true,
|
||||
"compression-multiple-chunks.tentative.any.worker.html": true,
|
||||
"compression-output-length.tentative.any.html": true,
|
||||
"compression-output-length.tentative.any.worker.html": true,
|
||||
"compression-stream.tentative.any.html": true,
|
||||
"compression-stream.tentative.any.worker.html": true,
|
||||
"compression-with-detach.tentative.window.html": true,
|
||||
"decompression-bad-chunks.tentative.any.html": [
|
||||
"chunk of type undefined should error the stream for deflate-raw",
|
||||
"chunk of type null should error the stream for deflate-raw",
|
||||
"chunk of type numeric should error the stream for deflate-raw",
|
||||
"chunk of type object, not BufferSource should error the stream for deflate-raw",
|
||||
"chunk of type array should error the stream for deflate-raw",
|
||||
"chunk of type SharedArrayBuffer should error the stream for deflate-raw",
|
||||
"chunk of type shared Uint8Array should error the stream for deflate-raw",
|
||||
"chunk of type invalid deflate bytes should error the stream for deflate-raw",
|
||||
"chunk of type invalid gzip bytes should error the stream for deflate-raw"
|
||||
],
|
||||
"decompression-bad-chunks.tentative.any.worker.html": [
|
||||
"chunk of type undefined should error the stream for deflate-raw",
|
||||
"chunk of type null should error the stream for deflate-raw",
|
||||
"chunk of type numeric should error the stream for deflate-raw",
|
||||
"chunk of type object, not BufferSource should error the stream for deflate-raw",
|
||||
"chunk of type array should error the stream for deflate-raw",
|
||||
"chunk of type SharedArrayBuffer should error the stream for deflate-raw",
|
||||
"chunk of type shared Uint8Array should error the stream for deflate-raw",
|
||||
"chunk of type invalid deflate bytes should error the stream for deflate-raw",
|
||||
"chunk of type invalid gzip bytes should error the stream for deflate-raw"
|
||||
],
|
||||
"decompression-buffersource.tentative.any.html": [
|
||||
"chunk of type ArrayBuffer should work for deflate-raw",
|
||||
"chunk of type Int8Array should work for deflate-raw",
|
||||
"chunk of type Uint8Array should work for deflate-raw",
|
||||
"chunk of type Uint8ClampedArray should work for deflate-raw",
|
||||
"chunk of type Int16Array should work for deflate-raw",
|
||||
"chunk of type Uint16Array should work for deflate-raw",
|
||||
"chunk of type Int32Array should work for deflate-raw",
|
||||
"chunk of type Uint32Array should work for deflate-raw",
|
||||
"chunk of type Float32Array should work for deflate-raw",
|
||||
"chunk of type Float64Array should work for deflate-raw",
|
||||
"chunk of type DataView should work for deflate-raw"
|
||||
],
|
||||
"decompression-buffersource.tentative.any.worker.html": [
|
||||
"chunk of type ArrayBuffer should work for deflate-raw",
|
||||
"chunk of type Int8Array should work for deflate-raw",
|
||||
"chunk of type Uint8Array should work for deflate-raw",
|
||||
"chunk of type Uint8ClampedArray should work for deflate-raw",
|
||||
"chunk of type Int16Array should work for deflate-raw",
|
||||
"chunk of type Uint16Array should work for deflate-raw",
|
||||
"chunk of type Int32Array should work for deflate-raw",
|
||||
"chunk of type Uint32Array should work for deflate-raw",
|
||||
"chunk of type Float32Array should work for deflate-raw",
|
||||
"chunk of type Float64Array should work for deflate-raw",
|
||||
"chunk of type DataView should work for deflate-raw"
|
||||
],
|
||||
"decompression-bad-chunks.tentative.any.html": true,
|
||||
"decompression-bad-chunks.tentative.any.worker.html": true,
|
||||
"decompression-buffersource.tentative.any.html": true,
|
||||
"decompression-buffersource.tentative.any.worker.html": true,
|
||||
"decompression-constructor-error.tentative.any.html": true,
|
||||
"decompression-constructor-error.tentative.any.worker.html": true,
|
||||
"decompression-correct-input.tentative.any.html": [
|
||||
"decompressing deflated (with -raw) input should work"
|
||||
],
|
||||
"decompression-correct-input.tentative.any.worker.html": [
|
||||
"decompressing deflated (with -raw) input should work"
|
||||
],
|
||||
"decompression-correct-input.tentative.any.html": true,
|
||||
"decompression-correct-input.tentative.any.worker.html": true,
|
||||
"decompression-corrupt-input.tentative.any.html": true,
|
||||
"decompression-corrupt-input.tentative.any.worker.html": true,
|
||||
"decompression-empty-input.tentative.any.html": [
|
||||
"decompressing deflate-raw empty input should work"
|
||||
],
|
||||
"decompression-empty-input.tentative.any.worker.html": [
|
||||
"decompressing deflate-raw empty input should work"
|
||||
],
|
||||
"decompression-split-chunk.tentative.any.html": [
|
||||
"decompressing splitted chunk into pieces of size 1 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 2 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 3 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 4 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 5 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 6 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 7 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 8 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 9 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 10 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 11 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 12 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 13 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 14 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 15 should work in deflate-raw"
|
||||
],
|
||||
"decompression-split-chunk.tentative.any.worker.html": [
|
||||
"decompressing splitted chunk into pieces of size 1 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 2 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 3 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 4 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 5 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 6 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 7 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 8 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 9 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 10 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 11 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 12 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 13 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 14 should work in deflate-raw",
|
||||
"decompressing splitted chunk into pieces of size 15 should work in deflate-raw"
|
||||
],
|
||||
"decompression-empty-input.tentative.any.html": true,
|
||||
"decompression-empty-input.tentative.any.worker.html": true,
|
||||
"decompression-split-chunk.tentative.any.html": true,
|
||||
"decompression-split-chunk.tentative.any.worker.html": true,
|
||||
"decompression-uint8array-output.tentative.any.html": true,
|
||||
"decompression-uint8array-output.tentative.any.worker.html": true,
|
||||
"decompression-with-detach.tentative.window.html": true,
|
||||
|
|
Loading…
Reference in a new issue