From 421ab5f05fcf0b2dbfa8ddffff7e717d26712ea8 Mon Sep 17 00:00:00 2001 From: v Date: Mon, 14 Jan 2019 11:52:18 +0300 Subject: [PATCH] xz -- optional dependency --- package.json | 6 ++++-- unzimmer.js | 47 +++++++++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index bf42882..dc6605c 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,9 @@ "zim", "pack" ], + "optionalDependencies": { + "xz": "^1.3.0" + }, "dependencies": { "animated-gif-detector": "^1.2.0", "cheerio": "*", @@ -41,8 +44,7 @@ "sharp": "^0.17.3", "sqlite": "^2.8.0", "sqlite3": "*", - "uuid": "*", - "xz": "^1.3.0" + "uuid": "*" }, "engines": { "node": ">=8.0.0" diff --git a/unzimmer.js b/unzimmer.js index 1ed9422..1ec7dd7 100755 --- a/unzimmer.js +++ b/unzimmer.js @@ -7,34 +7,26 @@ /* MODULE VARIABLE SECTION **********/ /************************************/ -const fs = require( 'fs-extra' ) -var mimeDb = require( 'mime-db' ); -var mime = require( 'mime-types' ); +const os = require('os') +const osProcess = require('process') +const osPath = require( 'path' ) +const expandHomeDir = require( 'expand-home-dir' ) -const packageInfo = require('./package.json'); +const fs = require( 'fs-extra' ) +const mimeDb = require( 'mime-db' ) +const mime = require( 'mime-types' ) + +const packageInfo = require('./package.json') const genericPool = require( 'generic-pool' ) const asyncRead = require('promised-read').read const cheerio = require('cheerio') const command = require('commander') -const osProcess = require('process') -var osPath = require( 'path' ); -var expandHomeDir = require( 'expand-home-dir' ); -//~ var lzma = require('lzma-native'); -var lzma = require('xz'); -//~ var lzma = require('node-liblzma'); -var csvOutput = require('csv-stringify'); +const csvOutput = require('csv-stringify') const moment = require("moment") require("moment-duration-format") -var srcPath; -var outPath; -var src; // input file reader - -var articles = null; -var metadata = []; - const startTime = Date.now() function elapsedStr( from , to = Date.now()) { @@ -54,6 +46,25 @@ function fatal ( ...args ) { osProcess.exit( 1 ) } +//~ var lzma = require('lzma-native') +try { + var lzma = require('xz') +} catch (er) { + if ( os.type() == 'Windows_NT' ) { + fatal( 'Module "xz" is not available on Windows' ) + } else { + fatal( 'Module "xz" is required' ) + } +} +//~ var lzma = require('node-liblzma') + +var srcPath; +var outPath; +var src; // input file reader + +var articles = null; +var metadata = []; + function readUInt64LE(buf, offset) { var lowBits = buf.readUInt32LE(offset); var highBits = buf.readUInt32LE(offset + 4);