Nerd Post: The plot thickens with the filesystem
So in my earlier post (http://8bitorange.tumblr.com/post/6520843543/nerd-alert-web-workers-and-the-filesystem) I wrote about some issues I hit with web workers and filesystems. I talked to a couple of friends and the web workers may have just been me non-intelligently spawning to many workers at a single time. I will be revisiting that at a later date. But the files with a # in the name intrigued me. So I put a little test together today with the following files:
- a.rtf
- a^.rtf
- a-.rtf
- a,.rtf
- a!.rtf
- a’.rtf
- a().rtf
- a&.rtf
- a%.rtf
- a$.rtf
- a#.rtf
- a|.rtf
- a*.rtf
I then ran them through the following script:
self.addEventListener("message", function(e){
var $this = self;
var file = e.data;
$this.webkitRequestFileSystem($this.TEMPORARY, 5*1024*1024, function(fs) {
fs.root.getFile(file.name, {create: true, exclusive: false}, function(fileEntry) {
fileEntry.file(function(f){
if(f.size !== 0){
var date = new Date();
var newName = date.getMilliseconds() + '_' + file.name;
fileEntry.copyTo(fs.root, newName, function(entry){
entry.file(function(newFile){
$this.postMessage({'success': true, 'msg': 'File Written', 'file': newFile});
});
});
} else {
fileEntry.createWriter(function(fileWriter) {
fileWriter.write(file);
$this.postMessage({'success': true, 'msg': 'File Written', 'file': file});
}, function(error){
$this.postMessage({'success': false, 'msg': 'write', 'error': error});
});
}
});
}, function(error){
$this.postMessage({'success': false, 'msg': 'get', 'error': error, 'file': file});
});
}, function(error){
$this.postMessage({'success': false, 'msg': 'filesystem', 'error': error});
});
}, false);
This is pretty basic stuff, I’m just copying the file with a modified name if it does exist and otherwise writing a new file if it doesn’t. I then return what file uploaded or whether there was an error. I came upon some interesting results that I thought I would share.
All files uploaded fine with exception of 3:
- a*.rtf
- a|.rtf
- a#.rtf (as expected….sort of)
The first two threw an error and died, which is fine, now I know, but the third did something odd and unexpected. It chopped the name at the “#” and just saved “a” as a file, dropping “#.rtf”.
I’m going to keep looking into this, but for now it appears that #,*,| are all characters that are not allowed in the filesystem in Chrome.
16 Notes/ Hide
-
lakelander liked this
-
8bitorange posted this