How can I modify a File

36 views
Skip to first unread message

toucht...@gmail.com

unread,
Apr 14, 2014, 11:38:37 AM4/14/14
to phon...@googlegroups.com
Hey everybody !
I have a terrible problem. I'm using the fileSystem plugin to write on a file, i'm able to append text without any problem, but the problem is when I want to delete a certain part of the file, I din't find anything to help me with.
I'm using a local json file to save some articles, pictures,..(whatever you want). Every time the user clicks on the favourite button, i'm writing into the file this way :
var len = fileWriter.length;
if(len===0) {
    fileWriter.write('[{"id":"'+text+ '"}]');
}
else {
    fileWriter.seek(len-1);
    fileWriter.write(',{"id":"'+text+ '"}]');
}

But now, what i want to do is to be able to delete some id if the user doesn't want it anymore in his favourites.

Thank you for your help.
Message has been deleted

toucht...@gmail.com

unread,
Apr 16, 2014, 7:50:55 AM4/16/14
to phon...@googlegroups.com
up

Ezo Saleh

unread,
Apr 16, 2014, 8:05:41 AM4/16/14
to phon...@googlegroups.com
Hey,

Saving such settings into a file seems like a bad idea because its way easier to deal with JSON objects when they're in memory rather than in persisted form.

Perhaps, use Local Storage to save user data. If/When you need to sync that data externally you can dump it into a file then using JSON.stringify()?


On Wednesday, 16 April 2014 12:50:55 UTC+1, toucht...@gmail.com wrote:
up

toucht...@gmail.com

unread,
Apr 17, 2014, 12:18:51 PM4/17/14
to phon...@googlegroups.com
Thanks for your answer !
Well I'm actually using json object, i don't see the point. Since i'm also using angularJS, i'm just doing a $http.get() and i just need to work on it, seems pretty easy to deal with to me, no ?
Well, i'll take a look on the Local Storage, in the end I just need a json file^^
Reply all
Reply to author
Forward
0 new messages