How to use the hasha.fromFile function in hasha

To help you get started, we’ve selected a few hasha 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 dosyago / p2. / index.js View on Github external
app.post('/very-secure-manifest-convert', upload.single('pdf'), async (req, res) => {
  const {file:pdf} = req;

  // logging 
    log(req, {file:pdf.path});

  // hash check for duplicate files
    const hash = await hasha.fromFile(pdf.path);
    const viewUrl = `${req.protocol}://${req.get('host')}/uploads/${pdf.filename}.html`;
    console.log({hash});
    if ( State.Files.has(hash) ) {
      const existingViewUrl = State.Files.get(hash);
      log(req, {note:'File exists', hash, existingViewUrl});
      return res.end(existingViewUrl);
    } else {
      newFiles += 1;
      State.Files.set(hash, viewUrl);
      if ( newFiles % WAIT_NEW_FILES_BEFORE_DISK_SYNC == 0 ) {
        syncHashes(State.Files);
      }
    }

  // job start
  const subshell = spawn(CONVERTER, [pdf.path, uploadPath]);
github Step7750 / node-csgo-cdn / index.js View on Github external
async isFileDownloaded(path, sha1) {
        try {
            const hash = await hasha.fromFile(path, {algorithm: 'sha1'});

            return hash === sha1;
        }
        catch (e) {
            return false;
        }
    }
github cs-education / classTranscribe / modules / conversion_utils.js View on Github external
async function hash_file(filename, algo='sha256') {
    const hasha = require('hasha');

    return await hasha.fromFile(filename, { algorithm: algo }).then(hash => {
        return Promise.resolve(hash);
    });
}
github cs-education / classTranscribe / modules / conversion_utils.js View on Github external
async function hash_file(filename, algo) {
    const hasha = require('hasha');

    var hash = await hasha.fromFile(filename, { algorithm: algo });
    return hash;
}
github florentsolt / photos / lib / generate.js View on Github external
};
  }

  if (options.reverse) album.reverse = true;
  if (options.title) album.title = options.title;
  if (options.desc) album.description = options.desc;
  if (options.font) album.font = options.font;

  /*
   * Read directory in ./uploads and get checksums of .jpg
   */
  let checksums = [];
  for (let file of (await fs.readdir(folders.upload))) {
    if (path.extname(file) === '.jpg') {
      try {
        let hash = await hasha.fromFile(path.join(folders.upload, file), {algorithm: 'md5'});
        checksums.push([file, hash]);
      } catch (e) {
        checksums.push([file, false]);
      }
    }
  }

  let i = 0;
  for (let checksum of checksums) {
    i++;
    let file = checksum[0];
    let hash = checksum[1];

    if (album.pictures[i - 1] && hash !== false && album.pictures[i - 1].hash === hash) {
      /*
       * Skip existing files with same checksum
github balena-os / jetson-flash / lib / utils.js View on Github external
const fileHash = file => {
	return hasha.fromFile(file, {
		algorithm: 'sha1',
	});
};
github redhat-developer-tooling / developer-platform-install / browser / model / helpers / hash.js View on Github external
SHA256(filename) {
    return hasha.fromFile(filename, {algorithm: 'sha256'});
  }
}

hasha

Hashing made simple. Get the hash of a buffer/string/stream/file.

MIT
Latest version published 12 months ago

Package Health Score

74 / 100
Full package analysis