Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,9 @@ $ npm install picemb -g | |
|
||
## Example | ||
|
||
## API | ||
```bash | ||
picemb input output | ||
``` | ||
|
||
## License | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env node | ||
|
||
var nomnom = require("nomnom"); | ||
var img = require("../lib/imgbase64.js"); | ||
var fs = require("fs"); | ||
|
||
var PROGNAME = require("../package.json").name; | ||
|
||
var args = nomnom | ||
.script(PROGNAME) | ||
.options({ | ||
htmlfile: { | ||
position: 0, | ||
required: true, | ||
help: "HTML file with img tags." | ||
}, | ||
output: { | ||
position: 1, | ||
required: true, | ||
help: "Output file." | ||
}, | ||
version: { | ||
abbr: "V", | ||
flag: true, | ||
callback: function() { | ||
return PROGNAME + " " + require("../package.json").version; | ||
}, | ||
help: "Show version and quit." | ||
} | ||
}) | ||
.parse(); | ||
|
||
try { | ||
var html = fs.readFile(args.htmlfile, "utf8", _); | ||
var outStream = fs.createWriteStream( | ||
args.output, {flags: "w+", encoding: "utf8"}); | ||
var imgCrit = /(<img [^\/]*src=)(?:(["'])([^"']+)(["']))/g; | ||
var res, offset = 0; | ||
while ((res = imgCrit.exec(html)) != null) { | ||
outStream.write(html.substring(offset, res.index)); | ||
outStream.write(res[1]); | ||
outStream.write(res[2]); | ||
outStream.write(img.imgToDataProtocol(res[3], _)); | ||
outStream.write(res[4]); | ||
offset = imgCrit.lastIndex; | ||
} | ||
outStream.end(html.substring(offset)); | ||
} catch (e) { | ||
console.error(e.message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,49 @@ | ||
#!/usr/bin/env node | ||
/*** Generated by streamline 0.4.11 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb,__trap=__rt.__trap,__tryCatch=__rt.__tryCatch; (function main(_) { var nomnom, img, fs, PROGNAME, args, html, outStream, imgCrit, res, offset; var __frame = { name: "main", line: 1 }; return __func(_, this, arguments, main, 0, __frame, function __$main() { | ||
nomnom = require("nomnom"); | ||
img = require("../lib/imgbase64.js"); | ||
fs = require("fs"); | ||
|
||
var nomnom = require("nomnom"); | ||
var img = require("../lib/imgbase64.js"); | ||
var fs = require("fs"); | ||
|
||
var args = nomnom | ||
.script("picemb") | ||
.options({ | ||
imgpath: { | ||
position: 0, | ||
required: true, | ||
help: "Image to convert to data protocol." | ||
}, | ||
version: { | ||
abbr: "V", | ||
flag: true, | ||
callback: function() {return "picemb " + require("../package.json").version;}, | ||
help: "Show version" | ||
} | ||
}).parse(); | ||
|
||
img.imgToDataProtocol(args.imgpath, function(err, text) { | ||
if (err) return console.error(err); | ||
console.log(text); | ||
}); | ||
PROGNAME = require("../package.json").name; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
args = nomnom.script(PROGNAME).options({ htmlfile: { position: 0, required: true, help: "HTML file with img tags." }, output: { position: 1, required: true, help: "Output file." }, version: { abbr: "V", flag: true, callback: function() { return ((PROGNAME + " ") + require("../package.json").version); }, help: "Show version and quit." } }).parse(); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$main() { | ||
|
||
|
||
return fs.readFile(args.htmlfile, "utf8", __cb(_, __frame, 32, 13, function ___(__0, __1) { html = __1; | ||
outStream = fs.createWriteStream(args.output, { | ||
flags: "w+", encoding: "utf8" }); | ||
imgCrit = /(<img [^\/]*src=)(?:(["'])([^"']+)(["']))/g; | ||
offset = 0; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$main() { __more = false; | ||
var __4 = ((res = imgCrit.exec(html)) != null); if (__4) { | ||
outStream.write(html.substring(offset, res.index)); | ||
outStream.write(res[1]); | ||
outStream.write(res[2]); | ||
return img.imgToDataProtocol(res[3], __cb(_, __frame, 41, 20, function ___(__0, __2) { outStream.write(__2); | ||
outStream.write(res[4]); | ||
offset = imgCrit.lastIndex; while (__more) { __loop(); }; __more = true; }, true)); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$main() { | ||
|
||
outStream.end(html.substring(offset)); __then(); }); }, true)); }); })(function ___(e, __result) { __tryCatch(_, function __$main() { if (e) { | ||
|
||
console.error(e.message); __then(); } else { _(null, __result); } ; }); }); })(function ___() { __tryCatch(_, _); }); });}).call(this, __trap); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters