Skip to content

Using memory-based file-like object (BytesIO) #25

Description

@cccassidy

Is there a way to load a file-like object from memory? Looking for a way to work around local storage limitations and improve performance by using memory for input/output operations. The following example using a BytesIO object returns an error from the library.

This is with Python 3.6 and ecCodes 2.17.0.

Thanks!

f= open('file.grib','rb')
buffer = io.BytesIO(f.read())
codes_grib_new_from_file(buffer)
---------------------------------------------------------------------------
UnsupportedOperation Traceback (most recent call last)
<ipython-input-25-b3e3d2be12aa> in <module>
----> 1 codes_grib_new_from_file(stream)~/.local/lib/python3.6/site-packages/gribapi/gribapi.py in grib_new_from_file(fileobj, headers_only)
403 # err, h = err_last(lib.grib_new_from_file)(ffi.NULL, fileobj, headers_only)
404 err, h = err_last(lib.codes_handle_new_from_file)(
--> 405 ffi.NULL, fileobj, CODES_PRODUCT_GRIB
406 )
407 if err:~/.local/lib/python3.6/site-packages/gribapi/gribapi.py in wrapper(*args)
150 err = ffi.new("int *")
151 args += (err,)
--> 152 retval = func(*args)
153 return err[0], retval
154UnsupportedOperation: fileno

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions