89 lines
1.9 KiB
HTML
89 lines
1.9 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
</head>
|
|
<body>
|
|
<div id="stdout"></div>
|
|
</body>
|
|
<script src="../lib/require.js"></script>
|
|
<script>
|
|
require.config({
|
|
baseUrl: "../lib",
|
|
paths: {
|
|
"src": "../src"
|
|
}
|
|
});
|
|
|
|
require(["src/file-system"], function(IDBFS) {
|
|
|
|
var flags = 'FORMAT';
|
|
//var flags;
|
|
|
|
var fs = new IDBFS.FileSystem('local', flags);
|
|
var buffer = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
console.log('buffer', buffer);
|
|
var data = new Uint8Array(buffer.length);
|
|
console.log('data', data);
|
|
debugger;
|
|
fs.open('/myfile', 'w+', function(error, fd) {
|
|
if(error) throw error;
|
|
console.log('descriptor:', fd);
|
|
fs.write(fd, buffer, 0, buffer.length, 0, function(error, nbytes) {
|
|
console.log('write:', nbytes)
|
|
if(error) throw error;
|
|
fs.read(fd, data, 0, data.length, 0, function(error, nbytes) {
|
|
console.log('read:', nbytes);
|
|
console.log('data', data);
|
|
});
|
|
});
|
|
});
|
|
|
|
/*
|
|
function make_tmp_directory() {
|
|
return fs.mkdir('/tmp');
|
|
};
|
|
|
|
function remove_tmp_directory() {
|
|
return fs.rmdir('/tmp');
|
|
};
|
|
|
|
function create_tmp_file() {
|
|
return fs.open('/tmp/1', 'w+');
|
|
};
|
|
|
|
function print_fd(fd) {
|
|
console.log(fd);
|
|
return fd;
|
|
};
|
|
|
|
function write_data(fd) {
|
|
var data = new Uint8Array([1, 2, 3, 4]);
|
|
return fs.write(fd, data, 0, 4);
|
|
};
|
|
|
|
function close_tmp_file(fd) {
|
|
return fs.close(fd);
|
|
};
|
|
|
|
fs.promise.then(make_tmp_directory)
|
|
.then(function() {
|
|
var fd = fs.open('/tmp/1', 'w+');
|
|
|
|
function write_data() {
|
|
var data = new Uint8Array([1, 2, 3, 4]);
|
|
return fs.write(fd, data, 0, 4);
|
|
};
|
|
|
|
fd.promise.then(write_data);
|
|
})
|
|
.then(create_tmp_file)
|
|
.then(print_fd)
|
|
.then(write_data)
|
|
.then(function() { console.log('done'); })
|
|
.otherwise(function(error) { console.error(error, error.message, error.stack); });
|
|
*/
|
|
});
|
|
</script>
|
|
</html>
|