Mary
Mary

Reputation: 1125

Why can't I compress a string in Node.js

Using the following code:

const zlib = require('zlib');
const rawData = 'Hello World!';
zlib.deflateSync(rawData);

I'm getting the following error message:

  const isDuplex = this instanceof Stream.Duplex;
                        ^

TypeError: Right-hand side of 'instanceof' is not an object
    at Deflate.Readable (internal/streams/readable.js:193:25)
    at Deflate.Duplex (internal/streams/duplex.js:56:12)
    at Deflate.Transform (internal/streams/transform.js:117:10)
    at Deflate.ZlibBase (zlib.js:271:13)
    at Deflate.Zlib (zlib.js:669:12)
    at new Deflate (zlib.js:708:8)
    at Object.syncBufferWrapper [as deflateSync] (zlib.js:765:29)
    at Object.<anonymous> (/Users/donnguyen/aerofiler/web/src/zlib.js:3:6)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)

How do I resolve this error message?

Upvotes: 0

Views: 1092

Answers (1)

DevProgrammer
DevProgrammer

Reputation: 103

Please try to assign result to value named data.

const zlib = require('zlib');
const rawData = 'Hello World!';
const data = zlib.deflateSync(rawData);
console.log("result is ===>", data);

Upvotes: 1

Related Questions