Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda