ac-filehash
v1.0.1
Published
Create a hash for local files or from URL without loading the complete file
Downloads
9
Readme
AC Filehash
Create a hash from a file. The source can be a local file, ArrayBuffer, URL or an AWS s3 bucket/key.
This hash is created using 3 sections of the file - one at the beginning, one in the middle and one at the end. This way, a hash can be easily and fast created even for large files.
Usage
NodeJs
From local file
const acfh = require('ac-filehash')
let test = async () => {
let result = await acfh.getHash({
filePath: './test/BigBuckBunny.mp4'
})
// RESPONSE
{
error: undefined,
type: 'file',
hash: 'f9ccc07b4959f5698fd30913743aacd5',
fileSize: 158008374
}
}
test()
From URL
const acfh = require('ac-filehash')
let test = async () => {
let result = await acfh.getHash({
url: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4'
})
// RESPONSE
{
error: undefined,
type: 'url',
hash: 'f9ccc07b4959f5698fd30913743aacd5',
fileSize: 158008374
}
}
test()
From AWS S3
If no credentials are sent, the one's from your local AWS configuration are used.
const acfh = require('ac-filehash')
let test = async () => {
let result = await acfh.getHash({
bucket: 'mybucket',
key: 'mykey',
// optional credentials
credentials: {
accessKeyId: 'ABC',
secretAccessKey: 'SECRET',
// optional session token if you are using temporary credentials
sessionToken: 'token'
}
})
// RESPONSE
{
error: undefined,
type: 's3',
hash: 'f9ccc07b4959f5698fd30913743aacd5',
fileSize: 158008374
}
}
test()
Browser
const acfh = require('ac-filehash/browser')
const params = {
url: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4'
}
let test = async () => {
let result = await acfh.getHash({
url: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4'
})
// RESPONSE
{
error: undefined,
type: 'url',
hash: 'f9ccc07b4959f5698fd30913743aacd5',
fileSize: 158008374
}
let result = await acfh.getHash({
buffer: some_ArrayBuffer //<- e.g. ArrayBuffer generated from file through input field
})
// RESPONSE
{
error: undefined,
type: 'buffer',
hash: 'f9ccc07b4959f5698fd30913743aacd5',
fileSize: 158008374
}
}
test()
Links
License
MIT License Copyright © 2009-present, AdmiralCloud AG