mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 12:07:19 +00:00
Allow browser-based file reading to use deserializers for binary files
This commit is contained in:
parent
3a2ea9b98b
commit
05b32728bc
@ -1118,18 +1118,14 @@ exports.readFile = function(file,callback) {
|
|||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
// Onload
|
// Onload
|
||||||
reader.onload = function(event) {
|
reader.onload = function(event) {
|
||||||
// Deserialise the file contents
|
|
||||||
var text = event.target.result,
|
var text = event.target.result,
|
||||||
tiddlerFields = {title: file.name || "Untitled", type: type};
|
tiddlerFields = {title: file.name || "Untitled", type: type};
|
||||||
// Are we binary?
|
|
||||||
if(isBinary) {
|
if(isBinary) {
|
||||||
// The base64 section starts after the first comma in the data URI
|
|
||||||
var commaPos = text.indexOf(",");
|
var commaPos = text.indexOf(",");
|
||||||
if(commaPos !== -1) {
|
if(commaPos !== -1) {
|
||||||
tiddlerFields.text = text.substr(commaPos+1);
|
text = text.substr(commaPos + 1);
|
||||||
callback([tiddlerFields]);
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Check whether this is an encrypted TiddlyWiki file
|
// Check whether this is an encrypted TiddlyWiki file
|
||||||
var encryptedJson = $tw.utils.extractEncryptedStoreArea(text);
|
var encryptedJson = $tw.utils.extractEncryptedStoreArea(text);
|
||||||
if(encryptedJson) {
|
if(encryptedJson) {
|
||||||
@ -1141,7 +1137,6 @@ exports.readFile = function(file,callback) {
|
|||||||
// Otherwise, just try to deserialise any tiddlers in the file
|
// Otherwise, just try to deserialise any tiddlers in the file
|
||||||
callback(self.deserializeTiddlers(type,text,tiddlerFields));
|
callback(self.deserializeTiddlers(type,text,tiddlerFields));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
// Kick off the read
|
// Kick off the read
|
||||||
if(isBinary) {
|
if(isBinary) {
|
||||||
@ -1218,4 +1213,13 @@ exports.invokeUpgraders = function(titles,tiddlers) {
|
|||||||
return messages;
|
return messages;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
})();
|
||||||
|
t++) {
|
||||||
|
var upgrader = this.upgraderModules[t],
|
||||||
|
upgraderMessages = upgrader.upgrade(this,titles,tiddlers);
|
||||||
|
$tw.utils.extend(messages,upgraderMessages);
|
||||||
|
}
|
||||||
|
return messages;
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user