@ridi/epub-parser
Advanced tools
Comparing version 0.2.0-alpha.2 to 0.2.0-alpha.3
@@ -11,6 +11,2 @@ 'use strict'; | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
@@ -24,5 +20,5 @@ | ||
var _fs = require('fs'); | ||
var _fsExtra = require('fs-extra'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _fsExtra2 = _interopRequireDefault(_fsExtra); | ||
@@ -92,21 +88,20 @@ var _path = require('path'); | ||
_context.next = 2; | ||
return new _promise2.default(function (resolve, reject) { | ||
_fs2.default.readFile(fullPath, function (err, data) { | ||
if (err) { | ||
reject(err); | ||
} | ||
data = (0, _typecheck.isExists)(cryptoProvider) ? cryptoProvider.run(data, _path2.default.basename(fullPath)) : data; | ||
if ((0, _typecheck.isExists)(encoding)) { | ||
resolve(data.toString(encoding)); | ||
} else { | ||
resolve(data); | ||
} | ||
}); | ||
}); | ||
return _fsExtra2.default.readFile(fullPath); | ||
case 2: | ||
file = _context.sent; | ||
file = (0, _typecheck.isExists)(cryptoProvider) ? cryptoProvider.run(file, _path2.default.basename(fullPath)) : file; | ||
if (!(0, _typecheck.isExists)(encoding)) { | ||
_context.next = 6; | ||
break; | ||
} | ||
return _context.abrupt('return', file.toString(encoding)); | ||
case 6: | ||
return _context.abrupt('return', file); | ||
case 4: | ||
case 7: | ||
case 'end': | ||
@@ -125,3 +120,3 @@ return _context.stop(); | ||
}(), | ||
size: _fs2.default.lstatSync(fullPath).size | ||
size: _fsExtra2.default.lstatSync(fullPath).size | ||
}]); | ||
@@ -138,3 +133,3 @@ }, [])); | ||
case 0: | ||
if (!_fs2.default.lstatSync(input).isFile()) { | ||
if (!_fsExtra2.default.lstatSync(input).isFile()) { | ||
_context2.next = 6; | ||
@@ -145,3 +140,3 @@ break; | ||
if ((0, _typecheck.isExists)(cryptoProvider)) { | ||
input = cryptoProvider.run(_fs2.default.readFileSync(input), _path2.default.basename(input)); | ||
input = cryptoProvider.run(_fsExtra2.default.readFileSync(input), _path2.default.basename(input)); | ||
} | ||
@@ -148,0 +143,0 @@ _context2.next = 4; |
@@ -68,2 +68,3 @@ 'use strict'; | ||
var overwrite = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
var writeFile; | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
@@ -78,7 +79,31 @@ while (1) { | ||
_context3.next = 4; | ||
writeFile = function writeFile(entry, output) { | ||
// eslint-disable-line arrow-body-style | ||
return new _promise2.default(function (resolve, reject) { | ||
var writeStream = _fs2.default.createWriteStream(output); | ||
var onError = function onError() { | ||
reject(); | ||
writeStream.close(); | ||
}; | ||
entry.stream().on('data', function (data) { | ||
if ((0, _typecheck.isExists)(_this.cryptoProvider)) { | ||
writeStream.write(_this.cryptoProvider.run(data, _path2.default.basename(entry.path))); | ||
} else { | ||
writeStream.write(data); | ||
} | ||
}).on('error', onError).on('finish', function () { | ||
return writeStream.close(); | ||
}); | ||
writeStream.on('error', onError); | ||
writeStream.on('close', function () { | ||
resolve(); | ||
}); | ||
}); | ||
}; | ||
_context3.next = 5; | ||
return this.files.reduce(function (prevPromise, entry) { | ||
// eslint-disable-line arrow-body-style | ||
return prevPromise.then((0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { | ||
var output, dir, writeStream; | ||
var output, dir; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
@@ -97,17 +122,6 @@ while (1) { | ||
} | ||
writeStream = _fs2.default.createWriteStream(output); | ||
_context2.next = 5; | ||
return entry.stream().on('data', function (data) { | ||
if ((0, _typecheck.isExists)(_this.cryptoProvider)) { | ||
writeStream.write(_this.cryptoProvider.run(data, _path2.default.basename(entry.path))); | ||
} else { | ||
writeStream.write(data); | ||
} | ||
}).on('error', function () { | ||
writeStream.close(); | ||
}).on('finish', function () { | ||
writeStream.close(); | ||
}); | ||
_context2.next = 4; | ||
return writeFile(entry, output); | ||
case 5: | ||
case 4: | ||
case 'end': | ||
@@ -121,3 +135,3 @@ return _context2.stop(); | ||
case 4: | ||
case 5: | ||
case 'end': | ||
@@ -124,0 +138,0 @@ return _context3.stop(); |
{ | ||
"name": "@ridi/epub-parser", | ||
"version": "0.2.0-alpha.2", | ||
"version": "0.2.0-alpha.3", | ||
"description": "Common EPUB2 data parser for Ridibooks services written in ES6", | ||
@@ -42,2 +42,3 @@ "author": { | ||
"fast-xml-parser": "^3.11.2", | ||
"fs-extra": "^7.0.1", | ||
"he": "^1.1.1", | ||
@@ -44,0 +45,0 @@ "himalaya": "^1.1.0", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
156063
3486
9
+ Addedfs-extra@^7.0.1
+ Addedfs-extra@7.0.1(transitive)
+ Addedjsonfile@4.0.0(transitive)
+ Addeduniversalify@0.1.2(transitive)