tarabyte
tarabyte

Reputation: 19172

How to read in chunks of a file via chrome app?

I've got a reasonably small file (~50kB), that I'd like to manipulate in a chrome app at the byte level.

chrome.storage.local was my previous approach. This has a quota of ~5MB, which is plenty for this application, but the documentation made it seem like this should really be more for managing user settings, etc.

chrome.filesystem seems to be more for allowing the user to select a file. I'm reading through it now, but wanted to see if there's any guidance before I sink too much into one approach.

I would prefer to not have to store the file in a google drive account (this would be a dropbox or s3 link most likely).

Upvotes: 0

Views: 394

Answers (1)

Marc Rochkind
Marc Rochkind

Reputation: 3740

You have two choices:

  1. As the file is very small (you say around 50KB), you could just read it into your app and deal with it there. There are APIs for reading in a blob and then converting that to a byte array. A little web searching will get you to the APIs you need and most likely even examples

  2. I wouldn't really bother doing this with only 50KB, but once you have a blob, you can access slices of it. There are APIs for getting slices, too. While it isn't documented anywhere that I have seen, if you do this, the actual physical reading of the blob seems to be delayed, so taking a slice really does read only the part you want.

Sorry I'm not more specific about the APIs, but it's late at night here and I don't have time to get to my normal reference sites. However, as I said, both of the above are fairly conventional techniques and you'll find tons of stuff on them on the web. Much of it is in Stackoverflow, by the way.

Upvotes: 1

Related Questions