How to use the hasha.fromStream 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 garden-io / garden / garden-service / src / vcs / git.ts View on Github external
async hashObject(stats: Stats, path: string) {
    const stream = new PassThrough()
    const output = hasha.fromStream(stream, { algorithm: "sha1" })
    stream.push(`blob ${stats.size}\0`)

    if (stats.isSymbolicLink()) {
      // For symlinks, we follow git's behavior, which is to hash the link itself (i.e. the path it contains) as
      // opposed to the file/directory that it points to.
      stream.push(await readlink(path))
      stream.end()
    } else {
      createReadStream(path).pipe(stream)
    }

    return output
  }

hasha

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

MIT
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis