forked from vincekruger/tgs-to-gif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (31 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const fs = require('fs');
const path = require('path');
const puppeteer = require('puppeteer');
const renderLottie = require('puppeteer-lottie');
const tempy = require('tempy');
const zlib = require('zlib');
const unzip = function (inputPath, outputPath) {
const inputStream = fs.createReadStream(inputPath);
const outputStream = fs.createWriteStream(outputPath);
return new Promise((resolve, reject) => inputStream.pipe(zlib.createGunzip()).pipe(outputStream).on('finish', (err) => err ? reject(err) : resolve()));
};
const createBrowser = function ({chromiumPath, useSandbox = true}) {
return puppeteer.launch({
executablePath: chromiumPath,
args: useSandbox ? undefined : ['--no-sandbox'],
});
};
const convertFile = async function (inputPath, options = {}) {
const unzippedPath = tempy.file({extension: 'json'});
await unzip(inputPath, unzippedPath);
output = options.output || inputPath + '.gif';
await renderLottie({
path: unzippedPath,
output,
...options,
});
};
module.exports = {
createBrowser,
convertFile,
};