Skip to content

Allow tar.gz files to be loaded in memory, for later use (ex: served by a web server)

Notifications You must be signed in to change notification settings

gcoupelant/in-memory-targz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

in-memory-targz

Allow tar.gz files to be loaded in memory, for later use (ex: served by a web server)

Exemple

import InMemoryTargz from 'in-memory-targz';
import express from 'express';
import mime from 'mime';

const memTargz = InMemoryTargz.create('./data/archive.tar.gz');

const app = express();

app.use('/foo/bar', function(req, res) {
  // Strip the leading '/'
  const filename = req.path.slice(1);

  memTargz.getFile(filename)
    .then((fileBuffer) => {
      const contentType = mime.lookup(filename);
      res.set('Content-type', contentType);
      res.status(200).send(fileBuffer);
    })
    .catch((err) => {
      if (err && err.code === 'ENOENT') {
        return res.status(404).send('File not found');
      }
      res.status(400).send('An error occurred');
    });
});

app.listen(3000);
console.log('Server listening on port 3000');

About

Allow tar.gz files to be loaded in memory, for later use (ex: served by a web server)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published