var content="";
var input="";
var output="";
var outputJson="";
function readBlob(opt_startByte, opt_stopByte) {
var files = document.getElementById('files').files;
if (!files.length) {
alert('Please select a file!');
return;
}
var file = files[0];
var start = parseInt(opt_startByte) || 0;
var stop = parseInt(opt_stopByte) || file.size - 1;
var reader = new FileReader();
// If we use onloadend, we need to check the readyState.
reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
document.getElementById('byte_content').textContent = evt.target.result;
document.getElementById('byte_range').textContent =
['Read bytes: ', start + 1, ' - ', stop + 1,
' of ', file.size, ' byte file'].join('');
content = evt.target.result;
input = JSON.parse(content);
output = {
"c2array": true,
"size": [input.frames.length, 4, 1],
"data": input.frames.map(function(frame){
return [
[frame.image || ""],
[frame.title],
[frame.mediatype || ""],
[frame.thumb || ""]
];
})
};
// the "null, 4" part is just to pretty-format the json (indent 4 spaces)
var outputJson = JSON.stringify(output, null, 4);
}
};
var blob = file.slice(start, stop + 1);
reader.readAsBinaryString(blob);
}
document.querySelector('.readBytesButtons').addEventListener('click', function(evt) {
if (evt.target.tagName.toLowerCase() == 'button') {
var startByte = evt.target.getAttribute('data-startbyte');
var endByte = evt.target.getAttribute('data-endbyte');
readBlob(startByte, endByte);
}
}, false);
/*
{
"name": "werwer",
"frames": [
{
"title": "[Nieuwe Dia]",
"image": "\\files\\cacc0075a0c044cbc9ec.jpg", //without the filepath
"thumb": "\\files\\cacc0075a0c044cbc9ec.jpg", //thumb could be neglected
"mediatype": null, //same as thumb
"media": [] //same as thumb
},
{
"title": "[Nieuwe Dia]",
"image": null,
"thumb": null,
"mediatype": null,
"media": []
},
{
"title": "[Nieuwe Dia]",
"image": null,
"thumb": null,
"mediatype": null,
"media": []
},
{
"title": "[Nieuwe Dia]",
"image": null,
"thumb": null,
"mediatype": null,
"media": []
}
]
};
*/
var output = {
"c2array": true,
"size": [input.frames.length, 4, 1],
"data": input.frames.map(function(frame){
return [
[frame.image || ""],
[frame.title],
[frame.mediatype || ""],
[frame.thumb || ""]
];
})
};
// the "null, 4" part is just to pretty-format the json (indent 4 spaces)
var outputJson = JSON.stringify(output, null, 4);
console.log("test");
console.log(output);
document.getElementById("out").innerHTML = outputJson;[/code:11qmusfh]
This following code, it is by the way.