How to use the rw.readFileSync function in rw

To help you get started, we’ve selected a few rw 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 arachnys / athenapdf / cli / src / athenapdf.js View on Github external
})
    .parse(process.argv);

// Display help information by default
if (!process.argv.slice(2).length) {
    athena.outputHelp();
}

if (!uriArg) {
    console.error("No URI given. Set the URI to `-` to pipe HTML via stdin.");
    process.exit(1);
}

// Handle stdin
if (uriArg === "-") {
    let base64Html = new Buffer(rw.readFileSync("/dev/stdin", "utf8"), "utf8").toString("base64");
    uriArg = "data:text/html;base64," + base64Html;
// Handle local paths
} else if (!uriArg.toLowerCase().startsWith("http") && !uriArg.toLowerCase().startsWith("chrome://")) {
    uriArg = url.format({
        protocol: "file",
        pathname: path.resolve(uriArg),
        slashes: true
    });
}

// Generate SHA1 hash if no output is specified
if (!outputArg) {
    const shasum = crypto.createHash("sha1");
    shasum.update(uriArg);
    outputArg = shasum.digest("hex") + ".pdf";
}
github interactivethings / galaxy-of-covers / data / js / echonest.js View on Github external
//  callback(null, _.extend(version, {echonest: echonest}));
          //}
        })
        .catch(callback);

    })
    .catch(callback);


  }





var works = JSON.parse(rw.readFileSync(INPUT_WORKS, 'utf8'));

if (LIMIT_WORKS) {
  works = _.take(works, LIMIT_WORKS);
}



var worksRequests = works.map(function(work) {

  console.log('Processing work "' + work.title + '". Found ' + work.versions.length + ' versions');
  return new Promise(function (resolveWork, rejectWork) {

    var versions = work.versions;
    if (LIMIT_VERSIONS) {
      versions = _.take(versions, LIMIT_VERSIONS);
    }
github interactivethings / galaxy-of-covers / data / js / whosampled.js View on Github external
});

      Promise
        .all(pageRequests)
        .then(function(data) {
          callback(null, covers.concat(_.flatten(data)));
        }, callback);
    }, callback);
}

// I couldn't get the above stuff to work, so it's not used
// (but kept here in case it can be made to work)
// Instead, I wrote a script to read a list of pre-resolved urls
// that script starts here

var works = JSON.parse(rw.readFileSync(INPUT_FILE, 'utf8'));

var oUrls = [];

works.forEach(function(work) {
  work.versions.forEach(function(version) {
    if (version.echonest && version.echonest.whosampledId) {
      oUrls.push(BASE_URL + '/track/view/' + version.echonest.whosampledId)
    }
  })
})

function shiftAndResolve(list1, list2, callback) {
  var u = list1.shift();
  console.log('checking, ', u);
  resolver.resolve(u, function(err, url) {
    if (!err) list2.push(url)
github drd / jsxlate / bin / transform.js View on Github external
console.log("Transforms  nodes for translation. Reads/writes to stdin/out.");
    process.exit();
}

if (process.argv.length != 2
    || ~process.argv.indexOf("-h")
    || ~process.argv.indexOf("--help")) {
    showHelpAndExit();
}

var rw = require('rw');

var jsxlate = require('../lib/jsxlate.js');


var input = rw.readFileSync("/dev/stdin", "utf8");

try {
    console.log(jsxlate.transformMessageNodes(input));
} catch (e) {
    console.error(jsxlate.errorMessageForError(e));
    process.exit(1);
}
github drd / jsxlate / bin / translate.js View on Github external
if (process.argv.length != 4
    || process.argv[2] != "-t"
    || ~process.argv.indexOf("-h")
    || ~process.argv.indexOf("--help")) {
    showHelpAndExit();
}

var rw = require('rw');

var jsxlate = require('../lib/jsxlate.js');


var translationsFilename = process.argv[3];
var translations = JSON.parse(rw.readFileSync(translationsFilename, "utf8"));

var input = rw.readFileSync("/dev/stdin", "utf8");

try {
    console.log(jsxlate.translateMessages(input, translations));
} catch (e) {
    console.error(jsxlate.errorMessageForError(e));
    process.exit(1);
}
github drd / jsxlate / bin / bundle-messages.js View on Github external
var chalk = require('chalk');
var fs = require('fs');
var rw = require('rw');

var io = require('../build/io').default;
var filesFromMixedPaths = require('./filesFromMixedPaths');
var translateMessagesToBundle = require('../build/translate').default;

if (argv.f) {
    var format = argv.f;
} else {
    var fileChunks = argv.t.split('.');
    var format = fileChunks[fileChunks.length - 1];
}

var translations = rw.readFileSync(argv.t, "utf8");
var files = filesFromMixedPaths(argv._);
var bundle = {};
var missing = {};


files.forEach(function (filename) {
    var buffer = fs.readFileSync(filename, "utf8");
    try {
        var translationsForFile = translateMessagesToBundle(buffer, translations, { inputFormat: format });
    } catch (e) {
        console.error(chalk.bold.red("\nError in file " + filename + ":"));
        console.error(e);
        console.error(e.stack);
        e.node && console.error(generate(e.node));
        process.exit(1);
    }
github drd / jsxlate / bin / translate.js View on Github external
}

if (process.argv.length != 4
    || process.argv[2] != "-t"
    || ~process.argv.indexOf("-h")
    || ~process.argv.indexOf("--help")) {
    showHelpAndExit();
}

var rw = require('rw');

var jsxlate = require('../lib/jsxlate.js');


var translationsFilename = process.argv[3];
var translations = JSON.parse(rw.readFileSync(translationsFilename, "utf8"));

var input = rw.readFileSync("/dev/stdin", "utf8");

try {
    console.log(jsxlate.translateMessages(input, translations));
} catch (e) {
    console.error(jsxlate.errorMessageForError(e));
    process.exit(1);
}
github interactivethings / galaxy-of-covers / data / js / spotify.js View on Github external
duration: track.duration_ms,
            popularity: track.popularity,
            preview: track.preview_url,
            albumArtwork: _.max(track.album.images, function(d) { return d.width; }).url
          });
        },
        function(err) { return reject(err); }
      );
  });

}




var works = JSON.parse(rw.readFileSync(INPUT_WORKS, 'utf8'));

if (LIMIT_WORKS) {
  works = _.take(works, LIMIT_WORKS);
}



var worksRequests = works.map(function(work) {

  console.log('Processing work "' + work.title + '". Found ' + work.versions.length + ' versions');
  return new Promise(function (resolveWork, rejectWork) {

    var versions = work.versions;
    if (LIMIT_VERSIONS) {
      versions = _.take(versions, LIMIT_VERSIONS);
    }
github interactivethings / galaxy-of-covers / data / js / request-cache.js View on Github external
return new Promise(function(resolve, reject) {
    if (fs.existsSync(fname)) {
      console.log(' - cache hit for', hash);
      resolve(rw.readFileSync(fname, 'utf8'));
    } else {
      console.log(' - cache miss for', hash);
      makeRequest(url, fname, resolve, reject);
    }
  });
}
github interactivethings / galaxy-of-covers / data / js / musixmatch.js View on Github external
var trackData = JSON.parse(trackResponse);
      var genres = utils
        .getIn(trackData, ['message','body','track','primary_genres', 'music_genre_list'])
        .map(function(d) { return utils.getIn(d, ['music_genre', 'music_genre_name']); });

      version.musiXmatch = {
        id: mmId,
        genres: genres
      };
      return callback(null, version);
    }).catch(callback);
 }



var works = JSON.parse(rw.readFileSync(INPUT_WORKS, 'utf8'));

if (LIMIT_WORKS) {
  works = _.take(works, LIMIT_WORKS);
}



var worksRequests = works.map(function(work) {

  console.log('Processing work "' + work.title + '". Found ' + work.versions.length + ' versions');
  return new Promise(function (resolveWork, rejectWork) {

    var versions = work.versions;
    if (LIMIT_VERSIONS) {
      versions = _.take(versions, LIMIT_VERSIONS);
    }

rw

Now stdin and stdout are files.

BSD-3-Clause
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis