File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { nextTick } from "ext:deno_node/_next_tick.ts";
1414import {
1515 isAnyArrayBuffer ,
1616 isArrayBufferView ,
17+ isUint8Array ,
1718} from "ext:deno_node/internal/util/types.ts" ;
1819
1920var kRangeErrorMessage = "Cannot create final Buffer. It would be larger " +
@@ -158,6 +159,12 @@ export const inflateRawSync = function (buffer, opts) {
158159function sanitizeInput ( input ) {
159160 if ( typeof input === "string" ) input = Buffer . from ( input ) ;
160161
162+ if ( isArrayBufferView ( input ) && ! isUint8Array ( input ) ) {
163+ input = Buffer . from ( input . buffer , input . byteOffset , input . byteLength ) ;
164+ } else if ( isAnyArrayBuffer ( input ) ) {
165+ input = Buffer . from ( input ) ;
166+ }
167+
161168 if (
162169 ! Buffer . isBuffer ( input ) &&
163170 ( input . buffer && ! input . buffer . constructor === ArrayBuffer )
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
1010 createBrotliCompress ,
1111 createBrotliDecompress ,
1212 createDeflate ,
13+ gzip ,
1314 gzipSync ,
1415 unzipSync ,
1516} from "node:zlib" ;
@@ -210,3 +211,17 @@ Deno.test("createBrotliCompress params", async () => {
210211 ) ;
211212 assertEquals ( output . length , input . length ) ;
212213} ) ;
214+
215+ Deno . test ( "gzip() and gzipSync() accept ArrayBuffer" , async ( ) => {
216+ const deffered = Promise . withResolvers < void > ( ) ;
217+ const buf = new ArrayBuffer ( 0 ) ;
218+ let output : Buffer ;
219+ gzip ( buf , ( _err , data ) => {
220+ output = data ;
221+ deffered . resolve ( ) ;
222+ } ) ;
223+ await deffered . promise ;
224+ assert ( output ! instanceof Buffer ) ;
225+ const outputSync = gzipSync ( buf ) ;
226+ assert ( outputSync instanceof Buffer ) ;
227+ } ) ;
You can’t perform that action at this time.
0 commit comments