-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use BrowserFS to get a web page running #8
Comments
I get the following error when trying to get the BrowserFS example working using localstorage.
This is the HTML document. <!DOCTYPE html>
<html>
<head>
<!--<script src="compiled/lib/jquery-2.1.1.min.js" type="text/javascript"></script>-->
<!--
<script data-main="release/interpret-pyc" src="node_modules/requirejs/require.js"></script>
-->
<script src="compiled/lib/browserfs.min.js" type="text/javascript"></script>
</head>
<body>
<h1>Python Interpreter Test</h1>
<input type="file" onchange="handleFiles(this.files)"></input>
<div id='out'>
</div>
<script type="text/javascript">
BrowserFS.install(window);
var lsfs = new BrowserFS.FileSystem.LocalStorage();
BrowserFS.initialize(lsfs);
var fs = require('fs');
fs.writeFile('/sample.txt', 'Testing!', function(err){
if(err){ console.log(JSON.stringify(err)); }
});
/*
function handleFiles(fileList){
console.log(fileList[0]);
var reader = new FileReader();
reader.onload = (function(theFile){
return function(pyc){
console.log(pyc);
console.log(theFile.name);
console.log(pyc.target.result);
BrowserFS.install(window);
var lsfs = new BrowserFS.FileSystem.LocalStorage();
BrowserFS.initialize(lsfs);
var fs = require('fs');
fs.writeFile('test.txt', 'Testing!', function(err){
if(err){ console.log(err); }
});
//fs.writeFile('/'+theFile.name, pyc.target.result, function(err){
// if(err){ console.log(err); }
//});
};
})(fileList[0]);
reader.readAsBinaryString(fileList[0]);
}
*/
</script>
</body>
</html> |
I just tried this with One weird possibility is that local storage contains garbage data. Can you try flushing it with |
(Built code located here: https://github.com/jvilk/BrowserFS/releases/tag/v0.3.5 ) |
|
I'm using |
|
Sorry that was a typo. I did specify 'utf8'. |
Have you opened the debugger and verified that |
Oh, and I should mention: fs.writeFile('filename', ProgressEvent.target.result, 'utf8', cb) This states, "take the input JavaScript string, and write it to a file in UTF-8 format". So if it's not a JavaScript string, it won't work. |
I have verified that |
What error are you getting? Where is it getting thrown? Are you trying to write a binary file using UTF-8 encoding? Not all bytes are valid UTF-8 characters, and my UTF-8 encoding function verifies that it is not writing invalid characters. (EDIT: With that said, if it's already a JavaScript string (which are UTF-16), then... maybe there's a bug in my code.) Also, you should use |
The error is If you still think it's a problem BrowserFS should have detected. I'll give you any more information you need. I will refactor my code to to accept a NodeBuffer, rather than a file system. Muchas gracias! |
Oh, then it's likely not a code in my bug, just that you were doing the wrong thing w.r.t. writing the file in UTF-8 format, since
Not all bytes are valid UTF-8 characters, so who knows what Reading the file as an array buffer correctly preserves the data. |
That makes sense. |
Refactored to use NodeBuffer. All set. |
No description provided.
The text was updated successfully, but these errors were encountered: