| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 035a24e commit fa01fe6
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,6 +95,8 @@ function zlibBufferOnEnd() { | |||
| 95 | 95 | var err; | |
| 96 | 96 | if (this.nread >= kMaxLength) { | |
| 97 | 97 | err = new errors.RangeError('ERR_BUFFER_TOO_LARGE'); | |
| 98 | + } else if (this.nread === 0) { | ||
| 99 | + buf = Buffer.alloc(0); | ||
| 98 | 100 | } else { | |
| 99 | 101 | var bufs = this.buffers; | |
| 100 | 102 | buf = (bufs.length === 1 ? bufs[0] : Buffer.concat(bufs, this.nread)); | |
@@ -485,6 +487,9 @@ function processChunkSync(self, chunk, flushFlag) { | |||
| 485 | 487 | ||
| 486 | 488 | _close(self); | |
| 487 | 489 | ||
| 490 | + if (nread === 0) | ||
| 491 | + return Buffer.alloc(0); | ||
| 492 | + | ||
| 488 | 493 | return (buffers.length === 1 ? buffers[0] : Buffer.concat(buffers, nread)); | |
| 489 | 494 | } | |
| 490 | 495 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const zlib = require('zlib'); | ||
| 4 | + const { inspect, promisify } = require('util'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + const emptyBuffer = new Buffer(0); | ||
| 7 | + | ||
| 8 | + common.crashOnUnhandledRejection(); | ||
| 9 | + | ||
| 10 | + (async function() { | ||
| 11 | + for (const [ compress, decompress, method ] of [ | ||
| 12 | + [ zlib.deflateRawSync, zlib.inflateRawSync, 'raw sync' ], | ||
| 13 | + [ zlib.deflateSync, zlib.inflateSync, 'deflate sync' ], | ||
| 14 | + [ zlib.gzipSync, zlib.gunzipSync, 'gzip sync' ], | ||
| 15 | + [ promisify(zlib.deflateRaw), promisify(zlib.inflateRaw), 'raw' ], | ||
| 16 | + [ promisify(zlib.deflate), promisify(zlib.inflate), 'deflate' ], | ||
| 17 | + [ promisify(zlib.gzip), promisify(zlib.gunzip), 'gzip' ] | ||
| 18 | + ]) { | ||
| 19 | + const compressed = await compress(emptyBuffer); | ||
| 20 | + const decompressed = await decompress(compressed); | ||
| 21 | + assert.deepStrictEqual( | ||
| 22 | + emptyBuffer, decompressed, | ||
| 23 | + `Expected ${inspect(compressed)} to match ${inspect(decompressed)} ` + | ||
| 24 | + `to match for ${method}`); | ||
| 25 | + } | ||
| 26 | + })(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments