I currently have a web application that can read and write files on a Samsung Tizen TV v2.4 (Firmware: T-HKMLAKUC-1006.4)
Append hover does not seem to work.
I can do the following with no issues at all:
tizen.filesystem.resolve('documents/log.txt', (file) => {
file.openStream("w", (fs) => {
fs.write('Tizen .. '); // Works
console.log('written to log Tizen ... '); // View if its running the code block
// This block is ran as i get the console log from this function
}, (e) => {
console.log("Error " + e.message);
// No Errors thrown
}, "UTF-8");
}, (e) => {
// No Errors thrown
}, "a");
If i change the 'w' to 'a' which should append to the file the file is empty
tizen.filesystem.resolve('documents/log.txt', (file) => {
file.openStream("a", (fs) => {
console.log('written to log Tizen ... '); // View if its running the code block
// This block is ran as i get the console log from this function
fs.write('Tizen .. '); // When i read it nothing here
}, (e) => {
console.log("Error " + e.message);
}, "UTF-8");
});
Has anyone else seen this issue? Thanks
If i monitor the console logs from this function i get the following:
4:59:21 pm | YaBRm3kxLCctUNmhl034oLe0QQA= | "" // View the file
4:59:21 pm | YaBRm3kxLCctUNmhl034oLe0QQA= | "running append to file" // Run the append function
4:59:21 pm | YaBRm3kxLCctUNmhl034oLe0QQA= | "written to log Tizen ... " // Append function shows its running the success block
4:59:22 pm | YaBRm3kxLCctUNmhl034oLe0QQA= | "Tizen .. " // View the file (and its appended)
4:59:23 pm | YaBRm3kxLCctUNmhl034oLe0QQA= | "running append to file" // Run the append function again
4:59:23 pm | YaBRm3kxLCctUNmhl034oLe0QQA= | "written to log Tizen ... " // Shows its running the append function correctly
4:59:24 pm | YaBRm3kxLCctUNmhl034oLe0QQA= | "" // View the file and its empty
I think the bug in firmware, so append mode doesn't work correctly. I tested on firmware version T-HKMLAKUC-1008.2, the same error reproduce. My workaround, read current content from file, merge with new content and write again to file.
1) Create file
function createFile() {
tizen.filesystem.resolve('downloads', (dir) => {
var tizenFile = dir.createFile('/2017_10_08_13_13_21_826.log');
}, (error) => {
console.error("error resolve dir", error);
}, 'rw');
}
2) Read current content from file, append with newContents and write again to file.
function appendToFile(newContents) {
tizen.filesystem.resolve('downloads/2017_10_08_13_13_21_826.log', (tizenFile) => {
tizenFile.readAsText((currentContent) => {
var writeContents = currentContent + newContents;
tizenFile.openStream('w', (stream) => {
stream.write(writeContents);
stream.close();
}, (error) => {
console.error("error open stream content", error);
}, 'UTF-8');
}, (error) => {
console.error("error read current content", error);
}, 'UTF-8')
}, (error) => {
console.error("error resolve log file", error);
}, 'r');
}
Mode 'w' works correctly.