Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're under MacOS or Linux, you can use the <code>unzip</code> command to unzip from <code>stdin</code>.</p> <p>In this example I'm reading the zip file from the filesystem into a <code>Buffer</code> object but it works with a downloaded file as well:</p> <pre><code>// Get a Buffer with the zip content var fs = require("fs") , zip = fs.readFileSync(__dirname + "/test.zip"); // Now the actual unzipping: var spawn = require('child_process').spawn , fileToExtract = "test.js" // -p tells unzip to extract to stdout , unzip = spawn("unzip", ["-p", "/dev/stdin", fileToExtract ]) ; // Write the Buffer to stdin unzip.stdin.write(zip); // Handle errors unzip.stderr.on('data', function (data) { console.log("There has been an error: ", data.toString("utf-8")); }); // Handle the unzipped stdout unzip.stdout.on('data', function (data) { console.log("Unzipped file: ", data.toString("utf-8")); }); unzip.stdin.end(); </code></pre> <p>Which is actually just the node version of:</p> <pre><code>cat test.zip | unzip -p /dev/stdin test.js </code></pre> <p><strong>EDIT</strong>: It's worth noting that this will not work if the input zip is too big to be read in one chunk from stdin. If you need to read bigger files, and your zip file contains only one file, you can use <a href="http://www.info-zip.org/mans/funzip.html" rel="nofollow noreferrer">funzip</a> instead of <code>unzip</code>:</p> <pre><code>var unzip = spawn("funzip"); </code></pre> <p>If your zip file contains multiple files (and the file you want isn't the first one) I'm afraid to say you're out of luck. Unzip needs to seek in the <code>.zip</code> file since zip files are just a container, and unzip may just unzip the last file in it. In that case you have to save the file temporarily (<a href="https://github.com/bruce/node-temp" rel="nofollow noreferrer">node-temp</a> comes in handy).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload