Skip to content

pyshp 2.3 closing bytesio objects with Writer #244

Closed
@akrherz

Description

@akrherz

PyShp Version

2.3.0

Python Version

3.10

Your code

shpio = BytesIO()
shxio = BytesIO()
dbfio = BytesIO()
with shapefile.Writer(shx=shxio, dbf=dbfio, shp=shpio) as shp:
     ...
zio = BytesIO()
with zipfile.ZipFile(
        zio, mode="w", compression=zipfile.ZIP_DEFLATED
    ) as zf:
        zf.writestr("fn.shp", shpio.getvalue())
        zf.writestr("fn.shx", shxio.getvalue())
        zf.writestr("fn.dbf", dbfio.getvalue())

Full stacktrace

zf.writestr("fn.shp", shpio.getvalue())
ValueError: I/O operation on closed file.

Other notes

af1dee9 appears to now close any file objects. Perhaps my usage is not a best practice for BytesIO objects, but even in a context manager, the new pyshp code will close the bytesio objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions