-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (45 loc) · 1.37 KB
/
index.js
File metadata and controls
55 lines (45 loc) · 1.37 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
const utils = require('../utils');
let XzFileStream;
let XzUncompressStream;
function checkDependency() {
try {
require('lzma-native');
return true;
} catch (err) {
return false;
}
}
function throwIfNoDependency() {
if (!checkDependency()) {
throw new Error('lzma-native is required for xz compression/decompression. Please install it with: npm install lzma-native');
}
}
// Lazy load the implementation
function getImplementation() {
if (!XzFileStream) {
throwIfNoDependency();
XzFileStream = require('./file_stream');
XzUncompressStream = require('./uncompress_stream');
}
return { XzFileStream, XzUncompressStream };
}
exports.FileStream = function(opts) {
const { XzFileStream } = getImplementation();
return new XzFileStream(opts);
};
exports.UncompressStream = function(opts) {
const { XzUncompressStream } = getImplementation();
return new XzUncompressStream(opts);
};
exports.compressFile = function(source, dest, opts) {
throwIfNoDependency();
const { XzFileStream } = getImplementation();
return utils.makeFileProcessFn(XzFileStream)(source, dest, opts);
};
exports.uncompress = function(source, dest, opts) {
throwIfNoDependency();
const { XzUncompressStream } = getImplementation();
return utils.makeFileProcessFn(XzUncompressStream)(source, dest, opts);
};
exports.decompress = exports.uncompress;