Небольшой рефакторинг
This commit is contained in:
@@ -1,6 +1,28 @@
|
||||
const { spawn } = require('child_process');
|
||||
const fs = require('fs-extra');
|
||||
const crypto = require('crypto');
|
||||
const baseX = require('base-x');
|
||||
|
||||
const BASE36 = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
const bs36 = baseX(BASE36);
|
||||
|
||||
function toBase36(data) {
|
||||
return bs36.encode(Buffer.from(data));
|
||||
}
|
||||
|
||||
function fromBase36(data) {
|
||||
return bs36.decode(data);
|
||||
}
|
||||
|
||||
function getFileHash(filename, hashName, enc) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const hash = crypto.createHash(hashName);
|
||||
const rs = fs.createReadStream(filename);
|
||||
rs.on('error', reject);
|
||||
rs.on('data', chunk => hash.update(chunk));
|
||||
rs.on('end', () => resolve(hash.digest(enc)));
|
||||
});
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
@@ -54,6 +76,9 @@ function spawnProcess(cmd, opts) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
toBase36,
|
||||
fromBase36,
|
||||
getFileHash,
|
||||
sleep,
|
||||
randomHexString,
|
||||
touchFile,
|
||||
|
||||
Reference in New Issue
Block a user