fast-mhtml
Advanced tools
Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "fast-mhtml", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Parses mhtml files", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "mocha src/*.test.js", | ||
"test": "nyc --reporter=html mocha src/*.test.js", | ||
"lint": "eslint src/*.js", | ||
@@ -40,3 +40,4 @@ "benchmark": "node --expose-gc src/benchmark/benchmark.js", | ||
"husky": "^1.2.0", | ||
"mocha": "5.2.0" | ||
"mocha": "5.2.0", | ||
"nyc": "^13.1.0" | ||
}, | ||
@@ -43,0 +44,0 @@ "husky": { |
@@ -7,3 +7,4 @@ This package parses MHTML files into multiple HTML files. | ||
It supports a parser class that lets you view the files and a convenient `npm run serve` for serving files locally. | ||
It supports a parser class that lets you view the files and a convenient `npm run serve` for serving files locally which expects | ||
files to be in the demos directory (for example, try opening `http://localhost:8080/hn.mhtml`). | ||
@@ -21,3 +22,3 @@ ## Installation | ||
```js | ||
const { Parser } = require("./src/index"); | ||
const { Parser } = require("fast-mhtml"); | ||
const p = new Parser({ | ||
@@ -42,3 +43,3 @@ rewriteFn: filenamify, // default, urls are rewritten with this function | ||
```js | ||
const { Processor } = require("./src/index"); | ||
const { Processor } = require("fast-mhtml"); | ||
Processor.convert("one.mhtml"); // returns a promise that fulfills when the conversion is done | ||
@@ -52,3 +53,3 @@ ``` | ||
```js | ||
const { Parser } = require("./src/index.js"); | ||
const { Parser } = require("fast-mhtml"); | ||
const parser = new Parser({ }); // default | ||
@@ -97,2 +98,22 @@ const parser2 = new Parser({ | ||
``` | ||
Parser Serial | ||
Converted Example.com 1000 times. Memory(18.600929260253906) Average time: 0.494 | ||
Converted github 100 times. Memory(12.999603271484375) Average time: 21.1 | ||
Converted github large 10 times. Memory(13.364990234375) Average time: 73.1 | ||
Converted github unhandled rejection 10 times. Memory(13.101722717285156) Average time: 50.5 | ||
Converted mdn 20 times. Memory(16.388351440429688) Average time: 10.65 | ||
Converted wikipedia 20 times. Memory(15.015296936035156) Average time: 9.4 | ||
Converted hn 20 times. Memory(14.008590698242188) Average time: 1.55 | ||
Converted aliexpress 10 times. Memory(24.107528686523438) Average time: 297.2 | ||
Converted stackoverflow 10 times. Memory(12.956695556640625) Average time: 42.7 | ||
Parser Parallel 30 | ||
Converted Example.com in p=30. Memory(12.03277587890625) Average time: 0.3 | ||
Converted github in p=30. Memory(40.22245788574219) Average time: 19.566666666666666 | ||
Converted github large in p=30. Memory(24.891983032226562) Average time: 56.5 | ||
Converted github unhandled rejection in p=30. Memory(42.90928649902344) Average time: 39.86666666666667 | ||
Converted mdn in p=30. Memory(34.61607360839844) Average time: 7.9 | ||
Converted wikipedia in p=30. Memory(25.89984893798828) Average time: 6.033333333333333 | ||
Converted hn in p=30. Memory(15.358741760253906) Average time: 0.7666666666666667 | ||
Converted aliexpress in p=30. Memory(46.56867218017578) Average time: 139.9 | ||
Converted stackoverflow in p=30. Memory(60.3638916015625) Average time: 25.9 | ||
``` |
@@ -1,6 +0,2 @@ | ||
const filenamify = require('filenamify'); | ||
const co = require('bluebird').coroutine; | ||
const { promisifyAll } = require('bluebird'); | ||
const fs = promisifyAll(require('fs')); | ||
const MHTMLParser = require('./mhtmlParser'); // old code | ||
const Processor = require('../processor'); | ||
@@ -7,0 +3,0 @@ |
@@ -67,2 +67,3 @@ module.exports = (encoding, body) => { | ||
decoded[j++] = lower; | ||
continue; | ||
} | ||
@@ -80,2 +81,3 @@ | ||
decoded[j++] = lower; | ||
continue; | ||
} | ||
@@ -82,0 +84,0 @@ const shifted = upperTranslated << 4; |
@@ -16,9 +16,6 @@ const { URL } = require('url'); // url isn't global in Node < 8 | ||
function generateIs(str) { | ||
str = str.split('').map(x => x.replace(':', 'COLON').replace('-', 'DASH').replace('<', 'ANGLE')); | ||
str = str.split('').map(x => x.replace(':', 'COLON')); | ||
const mapBack = (s) => { | ||
if (s === 'COLON') return ':'; | ||
if (s === 'DASH') return '-'; | ||
if (s === 'ANGLE') return '<'; | ||
return s; | ||
@@ -35,3 +32,2 @@ }; | ||
const isXlinkHref = generateIs('xlink:href'); | ||
//const isHttpEquiv = generateIs('http-equiv'); // not actually relevant for what we do | ||
const isHref = generateIs('href'); | ||
@@ -74,3 +70,2 @@ const isData = generateIs('data'); | ||
}; | ||
class Generator { | ||
@@ -379,2 +374,4 @@ constructor(data, mapping, baseUrl) { | ||
} | ||
/* istanbul ignore next */ | ||
dumpIf(fn = () => true, logger = false) { | ||
@@ -407,11 +404,2 @@ let next100 = this.data.slice(this.i, this.i + 100).toString(); | ||
// const data = Buffer.from("<html><body><img baba src='foo.html'></body></html>"); | ||
// const mapping = new Map([ | ||
// ["foo.html", "http://testim.io/bar.html"]]) | ||
// const g = new Generator(data, mapping); | ||
// g.parse(); | ||
// console.log(g.result().toString()); | ||
module.exports = Generator; |
@@ -115,19 +115,19 @@ const cheerio = require('cheerio'); | ||
// old and deprecated stuff | ||
// old and deprecated stuff, skipped | ||
$('meta[http-equiv=refresh]').each((i, el) => { | ||
el = $(el); | ||
const re = /(\d)+; ?URL='?([^']*)'?/gi; | ||
const [, seconds, url] = re.exec(el.attr('content')); | ||
const link = new URL(url, baseUrl).toString(); | ||
const mapped = resourcesMap.get(link) || link; | ||
el.attr('content', `${seconds}; url=${mapped}`); | ||
}); | ||
// $('meta[http-equiv=refresh]').each((i, el) => { | ||
// el = $(el); | ||
// const re = /(\d)+; ?URL='?([^']*)'?/gi; | ||
// const [, seconds, url] = re.exec(el.attr('content')); | ||
// const link = new URL(url, baseUrl).toString(); | ||
// const mapped = resourcesMap.get(link) || link; | ||
// el.attr('content', `${seconds}; url=${mapped}`); | ||
// }); | ||
$('object[data]').each((i, el) => { | ||
el = $(el); | ||
const link = new URL(el.attr('data'), baseUrl).toString(); | ||
const mapped = resourcesMap.get(link) || link; | ||
el.attr('data', mapped); | ||
}); | ||
// $('object[data]').each((i, el) => { | ||
// el = $(el); | ||
// const link = new URL(el.attr('data'), baseUrl).toString(); | ||
// const mapped = resourcesMap.get(link) || link; | ||
// el.attr('data', mapped); | ||
// }); | ||
@@ -134,0 +134,0 @@ $('applet[code]').each((i, el) => { |
@@ -5,6 +5,4 @@ const filenamify = require('filenamify'); | ||
const CR = '\r'.charCodeAt(0); | ||
const LF = '\n'.charCodeAt(0); | ||
module.exports = class Parser { | ||
@@ -11,0 +9,0 @@ constructor(config = {}) { |
@@ -28,3 +28,3 @@ const fs = require('fs'); | ||
static serve(inputFileName, port = 8080) { | ||
static serve(port = 8080) { | ||
const app = express(); | ||
@@ -31,0 +31,0 @@ const fileCache = new Map(); |
251145
25
1317
115
2
7