Flipper/Applications/Custom (UL, RM, XFW)/RogueMaster/Scripts/storage.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-02-28 05:53:59 +00:00
let storage = require("storage");
let path = "/ext/storage.test";
2024-04-17 10:33:29 +00:00
function arraybuf_to_string(arraybuf) {
let string = "";
let data_view = Uint8Array(arraybuf);
for (let i = 0; i < data_view.length; i++) {
string += chr(data_view[i]);
}
return string;
}
2024-02-28 05:53:59 +00:00
print("File exists:", storage.exists(path));
print("Writing...");
2024-04-17 10:33:29 +00:00
// write(path, data, offset)
// If offset is specified, the file is not cleared, content is kept and data is written at specified offset
// Takes both strings and array buffers
2024-03-25 01:35:38 +00:00
storage.write(path, "Hello ");
2024-02-28 05:53:59 +00:00
print("File exists:", storage.exists(path));
2024-03-25 01:35:38 +00:00
// Append will create the file even if it doesnt exist!
2024-04-17 10:33:29 +00:00
// Takes both strings and array buffers
2024-03-25 01:35:38 +00:00
storage.append(path, "World!");
2024-02-28 05:53:59 +00:00
print("Reading...");
2024-04-17 10:33:29 +00:00
// read(path, size, offset)
// If no size specified, total filesize is used
// If offset is specified, size is capped at (filesize - offset)
2024-02-28 05:53:59 +00:00
let data = storage.read(path);
2024-04-17 10:33:29 +00:00
// read returns an array buffer, to allow proper usage of raw binary data
print(arraybuf_to_string(data));
2024-02-28 05:53:59 +00:00
print("Removing...")
storage.remove(path);
print("Done")
// There's also:
2024-04-17 10:33:29 +00:00
// storage.copy(old_path, new_path);
// storage.move(old_path, new_path);
// storage.mkdir(path);
2024-02-28 05:53:59 +00:00
// storage.virtualInit(path);
// storage.virtualMount();
// storage.virtualQuit();