views:

31

answers:

0

Ok, so I am downloading chunks of data via xhr and I want to store it locally for a chrome extension.

At first I was able to store it in localStorage, but then I needed to move on to larger chunks that localStorage can't handle.So I decided to store it in a Web Sql Database. However I was able to store the data in localStorage exactly as it was downloaded but when I try to store it in the database the data gets lost or I get an error.

Like so:

//this way the data gets lost because it is filtered to prevent SQL injection attacks
tx.executeSql('INSERT INTO files (id, content) VALUES (?,?)', [fileID,file]);

//this method gives an error (unrecognized token) because the data contains byte values in the string  
tx.executeSql('INSERT INTO files (id, content) VALUES (?, "' + file + '")', [id]);

The only other way I can think of getting the data into the database is by using btoa(file), and it works but I'm thinking that the performance will take a fairly substantial hit if it has to do an btoa / atob every time the data is stored / used.

So my question is then, how do you store the data in the database without using btoa, or if that's not possible how much performance does btoa use?

I'm also fairly certain that localStorage uses SQLite as well as a Web Sql Database, so why can't I just put the data in the latter as easily as I can with localStorage?