Skip to content

Commit

Permalink
getting late, the last one still had a snafu
Browse files Browse the repository at this point in the history
  • Loading branch information
EffinMaggie committed Sep 27, 2014
1 parent 5fcf5ce commit 5c834db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions lib/reave.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@ var http = require('http'),
cheerio = require('cheerio'),
url = require('url');

function fetch (http, URL, pageCallback, binary) {
function fetch (http, URL, pageCallback, base64) {
http.get(URL, function(r) {
if (binary) {
r.setEncoding('binary');
var body;
if (base64) {
body = [];
}
else {
body = '';
}

var body = '';
var type = r.headers['content-type'];

r.on('data', function (chunk) {
body += chunk;
if (base64) {
body.push(chunk);
}
else {
body += chunk;
}
});

r.on('end', function () {
pageCallback(body, type);
pageCallback(base64 ? Buffer.concat(body).toString('base64') : body, type);
});
});
}
Expand All @@ -27,7 +35,7 @@ function replace ($, pageCallback) {
u = n.attr('src');
if (u) {
fetch(https, u, function(data, type) {
n.attr('src', 'data:' + type + ';base64,' + (new Buffer(data).toString('base64')));
n.attr('src', 'data:' + type + ';base64,' + data);
return replace($, pageCallback);
}, true);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reave",
"version": "0.1.2",
"version": "0.1.3",
"description": "Scripts to fetch and simplify blog content.",
"keywords": [
"cli",
Expand Down

0 comments on commit 5c834db

Please sign in to comment.