2

I have a front end javascript library into which I'm attempting to load a zip file. The libraries documentation suggests that if I wish to be loading a zip file from a URL (I do) then I need to have the data in an arraybuffer.

As I'm not a Javascript person I'm having some trouble discerning how I might be able to do this.

The code I believe that I ultimately need to use is the following, where I assume buffer is the name of my buffer:

shp(buffer).then(function(geojson){});
//or
shp.parseZip(buffer)->returns zip

So the question is, if I have a file at example.com/myfile.zip how do I use vanilla javascript to get that into an ArrayBuffer? I assume once that is done I'll have what I need to feed into that code snippet above.

Plenty of googleing keeps getting me results that don't seem relevant. The File_API docs by Mozilla don't provide an example that I can see.

anakaine
  • 1,188
  • 2
  • 14
  • 30

1 Answers1

1

You can use fetch.

fetch('example.com/myfile.zip').then(res => res.arrayBuffer()).then(arrayBuffer => {
    // use ArrayBuffer
});
Unmitigated
  • 76,500
  • 11
  • 62
  • 80