Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodejs express use streams

const fs = require("fs"),
   tar = require("tar-stream");

app.get("/fileFromTar/*", (req, res) => {
   const fileWanted = req.params[0],
      readStream = fs.createReadStream('myTarFile.tar'),
      extractor = tar.extract();

   extractor.on('entry', (header, stream, next) => {
      stream.on('end', next);

      if (header.name === fileWanted) {
         const { size } = header;
         res.set({
           "Content-Type": 'audio/flac', // or whichever one applies
           "Content-Length": size,
           "Content-Range": `bytes 0-${size}/${size}`
         });
         stream.pipe(res);
      }
      else stream.resume();
   });
   readStream.pipe(extractor);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: add atribut readonly on form js 
Javascript :: FTP upload local file 
Javascript :: runecape 
Javascript :: javascript list all declared variables 
Javascript :: javascript get script path name 
Javascript :: show tempdata in javascript 
Javascript :: adding number in an array using the .forEach() method in javascript 
Javascript :: span element converink href="plugins/jvectormap/jquery-jvectormap-1.2.2.css" rel="stylesheet" type="text/css" / <!-- Date Picker --ter 
Javascript :: shopify functions nodejs 
Javascript :: nodejs pub sub redis 
Javascript :: Logical Assignment Operator null coalescing 
Javascript :: vue block other script event listeners 
Javascript :: template.json input parameters 
Javascript :: escape exponential input number in js 
Javascript :: where in typeorm 
Javascript :: comment creer des switch en react js 
Javascript :: One component overlapping on other in react.js app 
Javascript :: how to add multiple quill rich text editor 
Javascript :: bytes to uppercase hex javascript 
Javascript :: Make an array from the HTML Collection to make it iterable 
Javascript :: conditional statement for node on internet and node local server 
Javascript :: how to get the total price of all product in cart using react 
Javascript :: Get physical path in javascript 
Javascript :: javascript keyup original src element 
Javascript :: hex decode javascript 
Javascript :: how to add heaeader to http angular client 
Javascript :: mindate from another datepicker 
Javascript :: how add element at beginning of array in javascript using splice 
Javascript :: check string length pixel "react" 
Javascript :: maxscript create new Layer 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =