Debian Codegraph @

testing/web-platform/mozilla/tests/compression/zstd/decompression-buffersource.tentative.any.js

raw
1 // META: global=window,worker
2
3 "use strict";
4
5 // The zstd-compressed bytes for the string "expected output!!!!".
6 // Note that four exclamation points are added to make the compressed data a multiple of 8 bytes,
7 // which is a requirement to test with Float64Array.
8 const compressedZstdBytes = [
9 0x28, 0xb5, 0x2f, 0xfd, 0x04, 0x58, 0x99, 0x00, 0x00, 0x65, 0x78, 0x70, 0x65,
10 0x63, 0x74, 0x65, 0x64, 0x20, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x21, 0x21,
11 0x21, 0x21, 0x2e, 0x4f, 0xe5, 0x2b,
12 ];
13
14 const bufferSourceChunksForZstd = [
15 {
16 name: "ArrayBuffer",
17 value: new Uint8Array(compressedZstdBytes).buffer,
18 },
19 {
20 name: "Int8Array",
21 value: new Int8Array(new Uint8Array(compressedZstdBytes).buffer),
22 },
23 {
24 name: "Uint8Array",
25 value: new Uint8Array(compressedZstdBytes),
26 },
27 {
28 name: "Uint8ClampedArray",
29 value: new Uint8ClampedArray(new Uint8Array(compressedZstdBytes).buffer),
30 },
31 {
32 name: "Int16Array",
33 value: new Int16Array(new Uint8Array(compressedZstdBytes).buffer),
34 },
35 {
36 name: "Uint16Array",
37 value: new Uint16Array(new Uint8Array(compressedZstdBytes).buffer),
38 },
39 {
40 name: "Int32Array",
41 value: new Int32Array(new Uint8Array(compressedZstdBytes).buffer),
42 },
43 {
44 name: "Uint32Array",
45 value: new Uint32Array(new Uint8Array(compressedZstdBytes).buffer),
46 },
47 {
48 name: "Float16Array",
49 value: new Float16Array(new Uint8Array(compressedZstdBytes).buffer),
50 },
51 {
52 name: "Float32Array",
53 value: new Float32Array(new Uint8Array(compressedZstdBytes).buffer),
54 },
55 {
56 name: "Float64Array",
57 value: new Float64Array(new Uint8Array(compressedZstdBytes).buffer),
58 },
59 {
60 name: "DataView",
61 value: new DataView(new Uint8Array(compressedZstdBytes).buffer),
62 },
63 ];
64
65 for (const chunk of bufferSourceChunksForZstd) {
66 promise_test(async t => {
67 const ds = new DecompressionStream("zstd");
68 const writer = ds.writable.getWriter();
69 const reader = ds.readable.getReader();
70
71 const writePromise = writer.write(chunk.value);
72 const writerClosePromise = writer.close();
73
74 const { value, done } = await reader.read();
75
76 assert_false(done, "Stream should not be done after reading valid data");
77
78 await writePromise;
79 await writerClosePromise;
80
81 const decompressedText = new TextDecoder().decode(value);
82 assert_equals(
83 decompressedText,
84 "expected output!!!!",
85 `The decompressed text should match the expected text when reading from ${chunk.name}`
86 );
87 }, `chunk of type ${chunk.name} should work for zstd decompression`);
88 }