-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started case study, some images are not working for b123.
- Loading branch information
Showing
11 changed files
with
78 additions
and
0 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
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,6 @@ | ||
let fs = require('fs'); | ||
if (process.argv.length != 3) { | ||
console.log("Usage: node base64EncodeImage.js file"); | ||
process.exit(1); | ||
} | ||
console.log(fs.readFileSync(process.argv[2]).toString('base64')); |
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,31 @@ | ||
// Writes a number of images in both src, base64, and base123 format. | ||
let fs = require('fs') | ||
, base123 = require('../base123') | ||
; | ||
|
||
const kNumImages = 1000 | ||
, kImgDir = 'img/' | ||
, kHeader = "<html><head><meta charset='utf-8'></head><body>" | ||
, kFooter = "</body></html>" | ||
, kBase123Script = '<script>function b123d(a){function i(a){a<<=1,f|=a>>>g,g+=7,g>=8&&(e.push(f),g-=8,f=a<<7-g&255)}for(var b=[0,10,13,34,92],d=64,e=[],f=0,g=0,h=a.charCodeAt(0),j=1;j<a.length;j++){var k=a.charCodeAt(j);if(k>127){var l=k>>>8&7;if(i(b[l]),j==a.length-1&&h&d)continue;i(127&k)}else i(k)}return e}document.querySelectorAll("[data-b123]").forEach(a=>{var b=a.dataset.b123,c=a.dataset.b123m||"image/png";inflated=new Uint8Array(b123d(b));var d=new Blob([inflated],{type:c}),e=URL.createObjectURL(d);a.src=e});</script>' | ||
; | ||
|
||
let outSrc = fs.createWriteStream('out.html') | ||
, outB64 = fs.createWriteStream('out-base64.html') | ||
, outB123 = fs.createWriteStream('out-base123.html') | ||
, outFiles = [outSrc, outB64, outB123] | ||
; | ||
|
||
outFiles.forEach((file) => { file.write(kHeader); }); | ||
for (let i = 0; i < kNumImages; i++) { | ||
outSrc.write('<img src="' + kImgDir + i + '.png" />'); | ||
let buf = fs.readFileSync(kImgDir + i + '.png'); | ||
let base64String = buf.toString('base64'); | ||
outB64.write('<img src="data:image/png;base64,'+ base64String + '" />'); | ||
let base123Data = base123.encodeFromBase64(base64String); // TODO: bad, encode from buffer. | ||
outB123.write('<img data-b123="'); | ||
outB123.write(new Buffer(new Uint8Array(base123Data))); | ||
outB123.write('">'); | ||
} | ||
outB123.write(kBase123Script); | ||
outFiles.forEach((file) => { file.end(kFooter); }); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 @@ | ||
let fs = require('fs') | ||
, http = require('http') | ||
, currentImageIndex = 0 | ||
; | ||
|
||
const url = 'http://unsplash.it/64?image=' | ||
, kNumImages = 1000 | ||
, kConcurrency = 8 | ||
; | ||
|
||
function fetchImage() { | ||
if (currentImageIndex >= kNumImages) return; | ||
let index = currentImageIndex++; | ||
console.log('Fetching image ' + index + '/' + kNumImages); | ||
http.get(url + index, (res) => { | ||
let imageData = Buffer.alloc(0); | ||
res.on('data', (chunk) => { imageData = Buffer.concat([imageData, chunk]); }); | ||
res.on('end', () => { | ||
fs.writeFile('img/' + index + '.png', imageData); | ||
fetchImage(); | ||
}); | ||
}); | ||
} | ||
|
||
// Each fetchImage will act as a separate thread fetching images. | ||
for (let i = 0; i < kConcurrency; i++) fetchImage(); |
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
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
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,5 @@ | ||
let base123 = require('../base123') | ||
, testData = require('./testData') | ||
; | ||
|
||
base123.encodeFromBase64(testData.base64.imgBug); |
Large diffs are not rendered by default.
Oops, something went wrong.