Last active
April 8, 2017 04:38
-
-
Save unusualbob/ac266f751ca3b78117e73eb1f6fb63b3 to your computer and use it in GitHub Desktop.
Script to extract images from hex photo recall export file
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
'use strict'; | |
var fs = require('fs'); | |
/* | |
Information about why this exists can be found here: | |
https://robriddle.io/extracting-images-from-photorecall-deluxe-files/ | |
*/ | |
var stringHex = fs.createReadStream('./myOutputFile.txt'); | |
var lastIndex = 0; | |
var imageBuffer = new Buffer(''); | |
var dirname = process.argv[2]; | |
if (!dirname) { | |
return console.log('Usage: ./imageExtractor.js <localDirectoryToExportImagesTo>'); | |
} | |
if (!fs.existsSync('./' + dirname)) { | |
fs.mkdirSync('./' + dirname); | |
} | |
var rowChunk = ''; | |
var leftOverChunk = ''; | |
stringHex.on('data', function (chunk) { | |
stringHex.pause(); | |
console.log('chunk'); | |
rowChunk += chunk.toString(); | |
if (rowChunk.indexOf('\n') === -1) { | |
return stringHex.resume(); | |
} | |
else { | |
var rows = rowChunk.toString().split('\n'); | |
leftOverChunk = rows[rows.length - 1]; | |
rows.pop(); | |
rows.forEach(function (row) { | |
row = row.split('|||'); | |
if (row.length !== 7) { | |
return; | |
} | |
var filename = row[0]; | |
var data = row[4]; | |
console.log('file', filename); | |
fs.appendFileSync('./' + dirname + '/img-' + filename + '.jpg', new Buffer(data, 'hex'), {encoding: 'binary'}); | |
}); | |
rowChunk = leftOverChunk; | |
stringHex.resume(); | |
} | |
}); | |
stringHex.on('end', function () { | |
var row = rowChunk.split('\n')[0]; | |
row = row.split('|||'); | |
if (row.length !== 7) { | |
return; | |
} | |
var filename = row[0]; | |
var data = row[4]; | |
fs.appendFileSync('./' + dirname + '/img-' + filename + '.jpg', new Buffer(data, 'hex'), {encoding: 'binary'}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment