mirror of https://github.com/tycrek/ass
- `auth.js` - `data.js` - `hash.js` - `thumbnail.js` - `vibrant.js`pull/62/head
parent
a16478f990
commit
2521ec6cf0
@ -1,17 +0,0 @@
|
||||
const fs = require('fs-extra');
|
||||
const crypto = require('crypto');
|
||||
const toArray = require('stream-to-array');
|
||||
const { log } = require('./utils');
|
||||
|
||||
/**
|
||||
* Generates a SHA1 hash for the provided file
|
||||
* @param {*} file The file to hash
|
||||
* @returns The SHA1 hash
|
||||
*/
|
||||
module.exports = (file) =>
|
||||
new Promise((resolve, reject) =>
|
||||
toArray((fs.createReadStream(file.path)))
|
||||
.then((parts) => Buffer.concat(parts.map((part) => (Buffer.isBuffer(part) ? part : Buffer.from(part)))))
|
||||
.then((buf) => crypto.createHash('sha1').update(buf).digest('hex')) // skipcq: JS-D003
|
||||
.then((hash) => log.debug(`Hash for ${file.originalname}`, hash, 'SHA1, hex').callback(resolve, hash))
|
||||
.catch(reject));
|
@ -0,0 +1,18 @@
|
||||
import { FileData } from './definitions';
|
||||
import fs from 'fs-extra';
|
||||
import crypto from 'crypto';
|
||||
import toArray from 'stream-to-array';
|
||||
import { log } from './utils';
|
||||
|
||||
/**
|
||||
* Generates a SHA1 hash for the provided file
|
||||
* @param {*} file The file to hash
|
||||
* @returns The SHA1 hash
|
||||
*/
|
||||
module.exports = (file: FileData) =>
|
||||
new Promise((resolve, reject) =>
|
||||
toArray((fs.createReadStream(file.path)))
|
||||
.then((parts: any[]) => Buffer.concat(parts.map((part: any) => (Buffer.isBuffer(part) ? part : Buffer.from(part)))))
|
||||
.then((buf: Buffer) => crypto.createHash('sha1').update(buf).digest('hex')) // skipcq: JS-D003
|
||||
.then((hash: String) => log.debug(`Hash for ${file.originalname}`, hash, 'SHA1, hex').callback(resolve, hash))
|
||||
.catch(reject));
|
Loading…
Reference in new issue