How to use the fs.createWriteStream function in fs

To help you get started, we’ve selected a few fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bestander / deploy-azure-cdn / src / deploy-task.js View on Github external
function gzipFile(source) {
    var tempFile;
    var deferred = Q.defer();
    var gzip = zlib.createGzip({
        level: 9 // maximum compression
    });
    var inp;
    var out;
    gzip.on('error', function (err) {
        deferred.reject(err);
    });

    inp = fs.createReadStream(source);
    tempFile = source + '.zip';
    out = fs.createWriteStream(tempFile);
    out.on('close', function () {
        deferred.resolve(tempFile);
    });
    inp.pipe(gzip).pipe(out);
    return deferred.promise;
}
github relotnek / medcellar / medcellar / server.js View on Github external
helmet = require('helmet'),
    lusca = require('lusca'),
    sanitizer = require('sanitizer'),
    passport = require('passport'),
    med = require('./routes/meds'),
    user = require('./routes/users'),
    https = require('https'),
    fs = require('fs'),
    compression = require('compression'),
    minify = require('express-minify'),
    expressHbs = require('express-handlebars'),
    config = require(process.env.MED_CONF);

var app = express();

var accessLogStream = fs.createWriteStream(config.accessLog, {
    flags: 'a'
});

app.configure(function() {
    app.set('port', process.env.PORT || 3000);
    app.use(express.logger({stream: accessLogStream}));
    app.use(compression());
    app.use(minify());
    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.methodOverride());
    app.use(express.session({
        secret: 'penandteller',
        cookie: {
            maxAge: 3600000 // see below
        }
github seanjs-stack / generator-seanjs / app / index.js View on Github external
var request = https.get(url, function(response) {
    if (response.statusCode !== 200) {
      log.red('Unable to download: ' + url);
      log.yellow('\nPlease download it manually and place it in ' + dest + '\n\n');
      if (cb) cb(false);
    } else {
      var file = fs.createWriteStream(dest, {
        flags: 'w'
      });
      response.pipe(file);
      file.on('finish', function() {
        log.green('Downloaded: ' + dest + '\n');
        file.close(cb); // close() is async, call cb after close completes.
      });

    }
  }).on('error', function(err) {
    log.red('Unable to download: ' + url);
github alexanderGugel / refreshify / bin / cmd.js View on Github external
function bundle () {
    var wb = w.bundle();
    wb.on('error', function (err) {
        notifyError(String(err));

        var writeStream = fs.createWriteStream(outfile);
        writeStream.on('error', notifyError);
        writeStream.on('end', refreshServer.refresh.bind(refreshServer));
        writeStream.write('window.BUNDLE_ERROR_MESSAGE = ' + JSON.stringify(String(err)) + ';\n');
        writeStream.write(clientSource);
    });

    var writeStream = fs.createWriteStream(dotfile);
    wb.pipe(writeStream);
    writeStream.write(clientSource);

    var bytes, time;
    w.on('bytes', function (b) { bytes = b; });
    w.on('time', function (t) { time = t; });
    
    wb.on('end', function () {
        fs.rename(dotfile, outfile, function (err) {
            if (err) return notifyError(err);
            if (verbose) {
                console.error(bytes + ' bytes written to ' + outfile + ' (' + (time / 1000).toFixed(2) + ' seconds)');
            }
            refreshServer.refresh();
        });
    });
github jonlb / node-build / tasks / copy.js View on Github external
copy: function(options,config,logger){
        var p = new Promise();
            newFile = fs.createWriteStream(options.to),
            oldFile = fs.createReadStream(options.from);
        
        newFile.on('open',function(fd){
           util.pump(oldFile,newFile, function(err){
               logger.info("File " + options.from + " copied to " + options.to);
               p.resolve(true);
           });
        });
        
        return p;

    }
};
github mailsac / mailsac-examples / list-attachments-and-download-them.js View on Github external
message.attachments.forEach((checksum) => {
                    const file = fs.createWriteStream(`${checksum}.eml`);
                    request(`https://mailsac.com/api/addresses/${address}/messages/${message._id}/attachments/${checksum}`)
                        .pipe(file);
                });
            }
github transloadit / transloadify / src / assemblies-create.js View on Github external
.then(mtime => {
        let outstream = fs.createWriteStream(outpath)
        outstream.mtime = mtime
        return outstream
      })
  }
github huridocs / uwazi / app / api / utils / files.js View on Github external
new Promise((resolve, reject) => {
    const filePath = path.join(configPaths.uploadedDocuments, fileName);
    const writeStream = fs.createWriteStream(filePath);
    readStream.pipe(writeStream)
    .on('finish', () => resolve(filePath))
    .on('error', reject);
  });
github zenparsing / skert / packages / parser / util / generate-unicode.js View on Github external
HTTP.get(url, response => {
    let out = FS.createWriteStream(filePath);
    response.pipe(out);
    response.on('end', callback);
  }).on('error', fail);
}
github mozilla / node-janus / lib / plugins / dom / gif2video.js View on Github external
function transcodeGif(source, callback) {
  var gifPath = temp.path({ suffix: '.gif' });

  var gifStream = fs.createWriteStream(gifPath);
  source.pipe(gifStream).on('finish', function() {
    var destPath = temp.path({ suffix: '.webm' });
    var ffmpeg = spawn('ffmpeg',
        ['-i', gifPath, '-vcodec', 'libvpx', destPath]);

    metrics.streamTimer(ffmpeg, 'transcode');

    ffmpeg.on('close', function(code) {
      fs.unlink(gifPath);

      if (code !== 0) {
        callback('Failed, exit code ' + code);
        return;
      }

      fs.stat(destPath, function(err, stats) {

fs

This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.

ISC
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis