forked from DebaucheryLibrarian/traxxx
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const config = require('config');
|
|
const { PassThrough } = require('stream');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const bhttp = require('bhttp');
|
|
const blake2 = require('blake2');
|
|
const sharp = require('sharp');
|
|
|
|
const url = 'https://thumbs.julesjordan.com/trial/content//upload/dl03/julesjordan/oil_overload_16_scene2//photos/alina_lopez_jules_jordan_com_77.jpg';
|
|
|
|
async function init() {
|
|
const hash = new blake2.Hash('blake2b');
|
|
hash.setEncoding('hex');
|
|
|
|
const res = await bhttp.get(url, {
|
|
stream: true,
|
|
});
|
|
|
|
const metaStream = sharp();
|
|
const hashStream = new PassThrough();
|
|
const target = fs.createWriteStream(path.join(config.media.path, 'temp', 'alina.jpg'));
|
|
const thumbTarget = fs.createWriteStream(path.join(config.media.path, 'temp', 'alina_thumb.jpg'));
|
|
|
|
hashStream.on('data', (chunk) => {
|
|
hash.write(chunk);
|
|
});
|
|
|
|
metaStream.clone()
|
|
.resize(320)
|
|
.pipe(thumbTarget);
|
|
|
|
const stream = res
|
|
.pipe(metaStream)
|
|
.pipe(hashStream)
|
|
.pipe(target);
|
|
|
|
stream.on('finish', () => {
|
|
hash.end();
|
|
const digest = hash.read();
|
|
|
|
console.log('stream', digest);
|
|
});
|
|
|
|
metaStream.on('info', (info) => {
|
|
console.log('info', info);
|
|
});
|
|
|
|
const stats = await metaStream.stats();
|
|
|
|
console.log('stats', stats);
|
|
}
|
|
|
|
init();
|