@twin.org/core 0.0.1-next.33 → 0.0.1-next.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +13 -35
- package/dist/esm/index.mjs +13 -35
- package/docs/changelog.md +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -3987,20 +3987,18 @@ class Compression {
|
|
|
3987
3987
|
static async compress(bytes, type) {
|
|
3988
3988
|
Guards.uint8Array(Compression._CLASS_NAME, "bytes", bytes);
|
|
3989
3989
|
Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
|
|
3990
|
-
const
|
|
3991
|
-
const
|
|
3992
|
-
|
|
3993
|
-
await
|
|
3994
|
-
const
|
|
3995
|
-
const chunks = await Compression.streamToChunks(reader);
|
|
3996
|
-
const concatenated = Uint8ArrayHelper.concat(chunks);
|
|
3990
|
+
const blob = new Blob([bytes]);
|
|
3991
|
+
const compressionStream = new CompressionStream(type);
|
|
3992
|
+
const compressionPipe = blob.stream().pipeThrough(compressionStream);
|
|
3993
|
+
const compressedBlob = await new Response(compressionPipe).blob();
|
|
3994
|
+
const compressedBytes = await compressedBlob.bytes();
|
|
3997
3995
|
// GZIP header contains a byte which specifies the OS the
|
|
3998
3996
|
// compression was performed on. We set this to 3 (Unix) to ensure
|
|
3999
3997
|
// that we produce consistent results.
|
|
4000
|
-
if (type === "gzip" &&
|
|
4001
|
-
|
|
3998
|
+
if (type === "gzip" && compressedBytes.length >= 10) {
|
|
3999
|
+
compressedBytes[9] = 3;
|
|
4002
4000
|
}
|
|
4003
|
-
return
|
|
4001
|
+
return compressedBytes;
|
|
4004
4002
|
}
|
|
4005
4003
|
/**
|
|
4006
4004
|
* Decompress a gzipped compressed byte array.
|
|
@@ -4011,31 +4009,11 @@ class Compression {
|
|
|
4011
4009
|
static async decompress(compressedBytes, type) {
|
|
4012
4010
|
Guards.uint8Array(Compression._CLASS_NAME, "compressedBytes", compressedBytes);
|
|
4013
4011
|
Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
|
|
4014
|
-
const
|
|
4015
|
-
const
|
|
4016
|
-
|
|
4017
|
-
await
|
|
4018
|
-
|
|
4019
|
-
const chunks = await Compression.streamToChunks(reader);
|
|
4020
|
-
return Uint8ArrayHelper.concat(chunks);
|
|
4021
|
-
}
|
|
4022
|
-
/**
|
|
4023
|
-
* Read the stream and create a list of chunks.
|
|
4024
|
-
* @param reader The reader to read the chunks from.
|
|
4025
|
-
* @returns The chunks.
|
|
4026
|
-
* @internal
|
|
4027
|
-
*/
|
|
4028
|
-
static async streamToChunks(reader) {
|
|
4029
|
-
const chunks = [];
|
|
4030
|
-
let done = false;
|
|
4031
|
-
do {
|
|
4032
|
-
const chunk = await reader.read();
|
|
4033
|
-
done = chunk.done;
|
|
4034
|
-
if (!done && Is.uint8Array(chunk.value)) {
|
|
4035
|
-
chunks.push(chunk.value);
|
|
4036
|
-
}
|
|
4037
|
-
} while (!done);
|
|
4038
|
-
return chunks;
|
|
4012
|
+
const blob = new Blob([compressedBytes]);
|
|
4013
|
+
const decompressionStream = new DecompressionStream(type);
|
|
4014
|
+
const decompressionPipe = blob.stream().pipeThrough(decompressionStream);
|
|
4015
|
+
const decompressedBlob = await new Response(decompressionPipe).blob();
|
|
4016
|
+
return decompressedBlob.bytes();
|
|
4039
4017
|
}
|
|
4040
4018
|
}
|
|
4041
4019
|
|
package/dist/esm/index.mjs
CHANGED
|
@@ -3985,20 +3985,18 @@ class Compression {
|
|
|
3985
3985
|
static async compress(bytes, type) {
|
|
3986
3986
|
Guards.uint8Array(Compression._CLASS_NAME, "bytes", bytes);
|
|
3987
3987
|
Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
|
|
3988
|
-
const
|
|
3989
|
-
const
|
|
3990
|
-
|
|
3991
|
-
await
|
|
3992
|
-
const
|
|
3993
|
-
const chunks = await Compression.streamToChunks(reader);
|
|
3994
|
-
const concatenated = Uint8ArrayHelper.concat(chunks);
|
|
3988
|
+
const blob = new Blob([bytes]);
|
|
3989
|
+
const compressionStream = new CompressionStream(type);
|
|
3990
|
+
const compressionPipe = blob.stream().pipeThrough(compressionStream);
|
|
3991
|
+
const compressedBlob = await new Response(compressionPipe).blob();
|
|
3992
|
+
const compressedBytes = await compressedBlob.bytes();
|
|
3995
3993
|
// GZIP header contains a byte which specifies the OS the
|
|
3996
3994
|
// compression was performed on. We set this to 3 (Unix) to ensure
|
|
3997
3995
|
// that we produce consistent results.
|
|
3998
|
-
if (type === "gzip" &&
|
|
3999
|
-
|
|
3996
|
+
if (type === "gzip" && compressedBytes.length >= 10) {
|
|
3997
|
+
compressedBytes[9] = 3;
|
|
4000
3998
|
}
|
|
4001
|
-
return
|
|
3999
|
+
return compressedBytes;
|
|
4002
4000
|
}
|
|
4003
4001
|
/**
|
|
4004
4002
|
* Decompress a gzipped compressed byte array.
|
|
@@ -4009,31 +4007,11 @@ class Compression {
|
|
|
4009
4007
|
static async decompress(compressedBytes, type) {
|
|
4010
4008
|
Guards.uint8Array(Compression._CLASS_NAME, "compressedBytes", compressedBytes);
|
|
4011
4009
|
Guards.arrayOneOf(Compression._CLASS_NAME, "type", type, Object.values(CompressionType));
|
|
4012
|
-
const
|
|
4013
|
-
const
|
|
4014
|
-
|
|
4015
|
-
await
|
|
4016
|
-
|
|
4017
|
-
const chunks = await Compression.streamToChunks(reader);
|
|
4018
|
-
return Uint8ArrayHelper.concat(chunks);
|
|
4019
|
-
}
|
|
4020
|
-
/**
|
|
4021
|
-
* Read the stream and create a list of chunks.
|
|
4022
|
-
* @param reader The reader to read the chunks from.
|
|
4023
|
-
* @returns The chunks.
|
|
4024
|
-
* @internal
|
|
4025
|
-
*/
|
|
4026
|
-
static async streamToChunks(reader) {
|
|
4027
|
-
const chunks = [];
|
|
4028
|
-
let done = false;
|
|
4029
|
-
do {
|
|
4030
|
-
const chunk = await reader.read();
|
|
4031
|
-
done = chunk.done;
|
|
4032
|
-
if (!done && Is.uint8Array(chunk.value)) {
|
|
4033
|
-
chunks.push(chunk.value);
|
|
4034
|
-
}
|
|
4035
|
-
} while (!done);
|
|
4036
|
-
return chunks;
|
|
4010
|
+
const blob = new Blob([compressedBytes]);
|
|
4011
|
+
const decompressionStream = new DecompressionStream(type);
|
|
4012
|
+
const decompressionPipe = blob.stream().pipeThrough(decompressionStream);
|
|
4013
|
+
const decompressedBlob = await new Response(decompressionPipe).blob();
|
|
4014
|
+
return decompressedBlob.bytes();
|
|
4037
4015
|
}
|
|
4038
4016
|
}
|
|
4039
4017
|
|
package/docs/changelog.md
CHANGED