Skip to content

Error: Can't find end of central directory : is this a zip file #266

@ir-fuel

Description

@ir-fuel

Describe the bug
I get a zip file error when reading the shapefile:

Error: Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html

To Reproduce
Here is the code:

import {Shapefile} from 'shapefile.js'
import fs from 'fs'
import path from 'path'
import os from 'os'
import axios from 'axios'

async function importZipCodesFromBPost() {
  const zipUrl = 'https://bgu.bpost.be/assets/9738c7c0-5255-11ea-8895-34e12d0f0423_x-shapefile_4326.zip'
  const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'zip-'))
  const zipFilePath = path.join(tempDir, 'data.zip')
  const zipResponse = await axios({
    url: zipUrl,
    method: 'GET',
    responseType: 'arraybuffer'
  })

  // Save the ZIP file to disk
  fs.writeFileSync(zipFilePath, zipResponse.data)
  console.log('ZIP file downloaded to:', zipFilePath)

  const shapefile = await Shapefile.load(zipFilePath)
  const shp = shapefile.parse('shp')
  const shx = shapefile.parse('shx')
  const dbf = shapefile.parse('dbf', {
    // Stop parsing the file when the byte position hits the field descriptors terminator
    // This allows you to quickly get the fields used in the .dbf file and ignore the remainder of the file
    properties: false
  })

  console.log(shp)
  console.log(shx)
  console.log(dbf)

  fs.unlinkSync(zipFilePath)
}

importZipCodesFromBPost().then(() => console.log('Done')).catch((err) => console.error(err))

Expected behavior
It should be read without problems

Desktop (please complete the following information):

  • OS: macOS 15.2
  • Node 22.11.0

Additional context
I can unzip the file with other tools

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions