Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
Import zipped file from http request, extract csv files and save as javascript array of objects

I wonder to get zipped data from an URL (https://developers.google.com/transit/gtfs/examples/sample-feed.zip) and convert each csv file to an Javascript Array of Objects binding.

For example, from routes.txt, I want to get:

    routes = [
    {
    route_id: 'AB'
    agency_id: 'DTA'
    route_short_name: '10'
    route_long_name: 'Airport - Bullfrog'
    route_desc: null
    route_type: 3
    route_url: null
    route_color: null
    route_text_color: null
    },
    {
    route_id: 'BFC'
    agency_id: 'DTA'
    route_short_name: '20'
    route_long_name: 'Bullfrog - Furnace Creek Resort'
    route_desc: null
    route_type: 3
    route_url: null
    route_color: null
    route_text_color: null
    }
...
    ]

All operations should be done directly in browser.

First, I tried to use Zip.js, but I think I don't know how to control promise use

let GTFS_URL = `http://sjc.infobus.engdb.com.br/infoponto/google_transit.zip`
        const GTFS_ZIP = new zip.ZipReader(new zip.HttpReader(GTFS_URL))

        const entries = await GTFS_ZIP.getEntries()
        console.log(entries)

        if (entries.length) {

// get first entry content as text by using a TextWriter
const text = await entries[0].getData(
        // writer
        new zip.TextWriter(),
        // options
        {
        onprogress: (index, max) => {
        // onprogress callback
        }
        }
);
        // text contains the entry data as a String
        console.log(text);
}

// close the ZipReader
    await reader.close();
    }
    )

Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules

Then, I tried JSzip solution

let GTFS_URL = `https://developers.google.com/transit/gtfs/examples/sample-feed.zip`

var zip = new JSZip();
zip.loadAsync(GTFS_URL)
        .then(function (GTFS_URL) {
            console.log(GTFS_URL)
            alert("OK")
        }, function () {
            alert("Not a valid zip file")
        });

I saw a lot of similar questions here in stackoverflow, but I couldn't get any of these to work the way I need

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!