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.

1 Answer 1

1

You can use fetch.

fetch('example.com/myfile.zip').then(res => res.arrayBuffer()).then(arrayBuffer => {
    // use ArrayBuffer
});
Sign up to request clarification or add additional context in comments.

1 Comment

@anakaine Happy to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.