Search code examples
javascripthtmlfirefoxfirefox-os

Generating File in Javascript for Firefox OS


I'm developping a Firefox OS application and i'm looking for generate a files with Javascript.

I know how to use DeviceStorage API and I also know that a file has property of Blob.

But I would like to generate files to full device memory. For example I would like to generate 1 file of 1Megabytes. But I have no idea how to do that. Someone has an idea ?

Thanks


Solution

  • For a 1mB file you will need to fill an array with 1000000 bytes.

    Then by using the constructor:

    var typedArray = new ArrayBuffer(1000000);
    var blob = new Blob([typedArray], {type: 'application/octet-binary'});
    

    You will end up with a 1mB blob of binary data that could be saved to a file using standard api.