title: Cannot delete File in use by read stream
body: <p>I'm trying to delete a folder after a POST request but i can't because it's in use by a read stream. I tried <code>.destroy();</code> and <code>.unpipe();</code> but it's still in use. </p>
  
  <p>I declare my read stream variable globally so i can destroy and unpipe it out of scope. </p>
  
  <pre><code>var file;
  </code></pre>
  
  <p>Here my Read Stream Function : </p>
  
  <pre><code>app.get('/api/video/:folder' , function(req, res) {
    var streamer = req.params.folder
    const path = 'D:/Clips/' + folder + '/clip.mp4'
    const stat = fs.statSync(path)
    const fileSize = stat.size
    const range = req.headers.range
  
    if (range) {
      const parts = range.replace(/bytes=/, "").split("-")
      const start = parseInt(parts[0], 10)
      const end = parts[1]
        ? parseInt(parts[1], 10)
        : fileSize-1
  
      const chunksize = (end-start)+1
      //const file = fs.createReadStream(path, {start, end})
      file = fs.createReadStream(path, {start, end})
      const head = {
        'Content-Range': `bytes ${start}-${end}/${fileSize}`,
        'Accept-Ranges': 'bytes',
        'Content-Length': chunksize,
        'Content-Type': 'video/mp4',
      }
  
      res.writeHead(206, head)
      file.pipe(res)
    } else {
      const head = {
        'Content-Length': fileSize,
        'Content-Type': 'video/mp4',
      }
      res.writeHead(200, head)
      fs.createReadStream(path).pipe(res)
    }
  });
  </code></pre>
  
  <p>and here is my delete request : </p>
  
  <pre><code>app.post('/api/delete', urlencodedParser, function(req,res){
    file.unpipe();
    file.destroy();
    var delFolder = req.body.folder;
    fsextra.removeSync('D:/Clips/' + delFolder);
  });
  </code></pre>
  
  <p>It's giving me error because the file is in use by read stream. </p>
  
  <p>How can i end read stream process ?</p>