Profiles·Public

jszip

semver>=3.8.0postconditions6functions4last verified2026-04-16coverage score80%

Postconditions — what we check

  • loadAsync · load-invalid-zip
    error
    Whendata is not valid zip data, is a Node.js stream, has unsupported features (multi-volume, password protected), or CRC32 mismatch when checkCRC32 is true
    ThrowsError — message describes the failure: 'JSZip can\'t accept a stream when loading a zip file.', 'Corrupted zip : CRC32 mismatch', or generic parse error
    Required handlingCaller MUST wrap loadAsync() in try-catch. Invalid, corrupted, or malicious zip files reject the promise. This is especially critical when loading user-uploaded files (docx, xlsx, pptx, zip) where content is untrusted.
    costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[1][2]
  • generateAsync · generate-unsupported-type
    error
    Whenrequested output type (uint8array, arraybuffer, blob, nodebuffer) is not available in current browser environment
    ThrowsError — type not supported in this environment
    Required handlingCaller MUST wrap generateAsync() in try-catch. In browser environments, check JSZip.support[type] before calling generateAsync with that type. On Node.js, nodebuffer is always supported.
    costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[3]
  • async · file-async-no-try-catch
    error
    Whenzip.files['name'].async(type) called without try-catch wrapping the await expression, in an async function that processes zip file contents
    ThrowsError — decompression failure from pako ('data error', 'invalid block type', 'invalid stored block lengths', 'invalid code lengths set'). Also throws Error('<type> is not supported by this platform') when output type unavailable in current environment (e.g. 'blob' requested in Node.js).
    Required handlingCaller MUST wrap .async() calls in try-catch. Files inside a zip archive may be individually corrupted, contain malformed DEFLATE data, or request an output type unavailable in the current runtime. This is especially critical when processing untrusted user-uploaded zip archives (docx, xlsx, pptx, zip) where individual file entries may be corrupted independently of the archive container. A zip that passes loadAsync() validation can still have individual entries that fail decompression.
    costmediumin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[4][5][6]
  • async · file-async-unsupported-type
    warning
    Whenzip.files['name'].async(type) called with an output type that is not supported in the current runtime environment: 'blob' in Node.js, 'uint8array'/'arraybuffer' in very old browsers without typed array support
    ThrowsError: '<type> is not supported by this platform' (thrown synchronously within the Promise from utils.checkSupport())
    Required handlingCaller SHOULD check JSZip.support[type] before calling .async(type) in browser environments where type availability varies. On Node.js, use 'nodebuffer' as the standard output type. The 'blob' type is only available in browser environments with Blob support.
    costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[4][7]
  • generateNodeStream · generate-node-stream-no-error-listener
    error
    Whenzip.generateNodeStream() called without registering an 'error' event listener on the returned ReadableStream, and/or without calling .pipe() to a writable stream that handles errors. DEFLATE compression of individual zip entries can fail mid-stream, emitting an 'error' event on the readable stream. Per Node.js EventEmitter semantics, an unhandled 'error' event causes an uncaught exception that crashes the process.
    ThrowsError emitted via stream 'error' event (not thrown — does NOT reject a Promise). Error message describes the compression failure. If no 'error' listener is registered on the returned stream, Node.js throws an unhandled exception: "Error: [compression error message]" and terminates the process.
    Required handlingCaller MUST register an 'error' event listener on the stream returned by generateNodeStream() before piping. When piping, also handle errors on the writable stream. The common pattern: zip.generateNodeStream({streamFiles:true}) .on('error', (err) => console.error('Zip error:', err)) .pipe(outputStream) .on('finish', () => console.log('Done')); Note: using .pipe() does NOT automatically propagate stream errors. Both the readable and writable streams must have separate error handlers.
    costhighin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[8][6][9]
  • generateNodeStream · generate-node-stream-unsupported-env
    error
    Whenzip.generateNodeStream() called in a browser environment or in a Node.js environment where the 'readable-stream' package is unavailable. The internal checkSupport('nodestream') check fails synchronously before the stream is created. Also throws if the 'type' option is set to anything other than 'nodebuffer' (e.g., 'blob', 'uint8array') — these types are explicitly rejected by toNodejsStream() with "is not supported by this method".
    ThrowsError thrown synchronously (not via stream): 'nodestream is not supported by this platform' when the environment lacks readable-stream support. Error thrown synchronously: '<type> is not supported by this method' when a non-nodebuffer type is passed via options.type.
    Required handlingUse generateNodeStream() only in Node.js server environments. Always use the default type ('nodebuffer'). In environments where browser/Node.js compatibility is uncertain, use generateAsync() instead which works in both environments. Wrap in try-catch if called with dynamic options to catch the synchronous throw.
    costlowin prodimmediate exceptionusers seeservice unavailablevisibilityvisible
    Sources[6][10]

Sources

Every postcondition cites at least one of these. Numbered to match the footnotes above.

  1. [1]stuk.github.io/jszip/documentationhttps://stuk.github.io/jszip/documentation/api_jszip/load_async.html
  2. [2]raw.githubusercontent.com/Stuk/jsziphttps://raw.githubusercontent.com/Stuk/jszip/master/lib/load.js
  3. [3]stuk.github.io/jszip/documentationhttps://stuk.github.io/jszip/documentation/api_jszip/generate_async.html
  4. [4]stuk.github.io/jszip/documentationhttps://stuk.github.io/jszip/documentation/api_zipobject/async.html
  5. [5]github.com/Stuk/jsziphttps://github.com/Stuk/jszip/blob/master/lib/zipObject.js
  6. [6]github.com/Stuk/jsziphttps://github.com/Stuk/jszip/blob/master/lib/stream/StreamHelper.js
  7. [7]github.com/Stuk/jsziphttps://github.com/Stuk/jszip/blob/master/lib/utils.js
  8. [8]github.com/Stuk/jsziphttps://github.com/Stuk/jszip/blob/master/lib/nodejs/NodejsStreamOutputAdapter.js
  9. [9]stuk.github.io/jszip/documentationhttps://stuk.github.io/jszip/documentation/api_jszip/generate_node_stream.html
  10. [10]github.com/Stuk/jsziphttps://github.com/Stuk/jszip/blob/master/lib/support.js
Need a different package?
Request a profile