How to use the fs.openSync 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 cloudant / couchbackup / test / citestutils.js View on Github external
function assertEncryptedFile(path, callback) {
  try {
    // Openssl encrypted files start with Salted
    const expectedBytes = Buffer.from('Salted');
    const buffer = Buffer.alloc(6);
    const fd = fs.openSync(path, 'r');
    // Read the first six bytes
    fs.readSync(fd, buffer, 0, 6, 0);
    fs.closeSync(fd);
    // Assert first 6 characters of the file are "Salted"
    assert.deepStrictEqual(buffer, expectedBytes, 'The backup file should be encrypted.');
    callback();
  } catch (err) {
    callback(err);
  }
}
github golang / tools / internal / lsp / protocol / typescript / code.ts View on Github external
function output(side: side) {
  // make sure the output file exists
  if (!side.outputFile) {
    side.outputFile = `ts${side.name}.go`;
    side.fd = fs.openSync(side.outputFile, 'w');
  }
  const f = function (s: string) {
    fs.writeSync(side.fd!, s);
    fs.writeSync(side.fd!, '\n');
  };
  f(u.computeHeader(false));
  f(`
        import (
          "context"
          "encoding/json"

          "golang.org/x/tools/internal/jsonrpc2"
          errors "golang.org/x/xerrors"
        )
        `);
  const a = side.name[0].toUpperCase() + side.name.substring(1);
github tatsy / markdown-it-imsize / lib / imsize / index.js View on Github external
function syncFileToBuffer(filepath) {
  var descriptor = fs.openSync(filepath, 'r');
  var size = fs.fstatSync(descriptor).size;
  var bufferSize = Math.min(size, MaxBufferSize);
  var buffer = new Buffer(bufferSize);
  fs.readSync(descriptor, buffer, 0, bufferSize, 0);
  fs.closeSync(descriptor);
  return buffer;
}
github google / tracing-framework / bin / generate-webgl-app.js View on Github external
var BinFile = function(path) {
  /**
   * File handle.
   * @type {number}
   * @private
   */
  this.fd_ = fs.openSync(path, 'w');

  /**
   * Current offset into the file.
   * @type {number}
   * @private
   */
  this.offset_ = 0;
};
github flurry / react-native-flurry-sdk / scripts / postinstall.js View on Github external
const getMd5 = (file) => {
  const bufferSize = 8192;
  const fd = fs.openSync(file, 'r');
  const hash = crypto.createHash('md5');
  const buffer = Buffer.alloc(bufferSize);

  try {
    let bytesRead;
    do {
      bytesRead = fs.readSync(fd, buffer, 0, bufferSize);
      hash.update(buffer.slice(0, bytesRead));
    } while (bytesRead === bufferSize);
  } finally {
    fs.closeSync(fd);
  }

  return hash.digest('hex');
}
github jareddr / PoECustomSoundtrack / poeCustomSoundtrack.js View on Github external
function writeFile(file, data) {
  try {
    const handle = fs.openSync(file, 'w');
    fs.writeFileSync(file, data);
    fs.closeSync(handle);
    return true;
  } catch (err) {
    return false;
  }
}
github microsoft / maker.js / packages / fonts / gen.js View on Github external
function write(fileName, content) {
    var fd = fs.openSync(path.join(fontRoot, fileName), 'w');
    fs.writeSync(fd, content);
    fs.closeSync(fd);
}
var sorted = sortKeys(out, {
github jsx / JSX / tool / preinstall.js View on Github external
function copyFileSync(srcFile, destFile) {
    var BUF_LENGTH = 64*1024;
    var buff = new Buffer(BUF_LENGTH);
    var fdr = fs.openSync(srcFile, 'r');
    var fdw = fs.openSync(destFile, 'w');
    var bytesRead = 1
    var pos = 0
    while (bytesRead > 0) {
        bytesRead = fs.readSync(fdr, buff, 0, BUF_LENGTH, pos);
        fs.writeSync(fdw,buff,0,bytesRead);
        pos += bytesRead;
      }
    fs.closeSync(fdr)
    fs.closeSync(fdw)
}

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