Show:

File operations specific to in-memory /vsimem/ files

Static Methods

gdal.vsimem.copy
(
  • data
  • filename
)

Create an in-memory /vsimem/ file copying a Buffer. This method copies the Buffer into GDAL's own memory heap creating an in-memory file that can be freely extended by GDAL. gdal.vsimem.set is the better choice unless the file needs to be extended.

The file will stay in memory until it is deleted with gdal.vsimem.release.

Parameters:

  • data Buffer

    A binary buffer containing the file data

  • filename String

    A file name beginning with /vsimem/

gdal.vsimem.release
(
  • filename
)
Buffer

Delete and retrieve the contents of an in-memory /vsimem/ file. This is a very fast zero-copy operation. It does not block the event loop. If the file was created by vsimem.set, it will return a reference to the same Buffer that was used to create it. Otherwise it will construct a new Buffer object with the GDAL allocated buffer as its backing store.

WARNING!

The file must not be open or random memory corruption is possible with GDAL <= 3.3.1. GDAL >= 3.3.2 will gracefully fail further operations and this function will always be safe.

Parameters:

  • filename String

    A file name beginning with /vsimem/

Returns:

Buffer:

A binary buffer containing all the data

gdal.vsimem.set
(
  • data
  • filename
)

Create an in-memory /vsimem/ file from a Buffer. This is a zero-copy operation - GDAL will read from the Buffer which will be protected by the GC even if it goes out of scope.

The file will stay in memory until it is deleted with gdal.vsimem.release.

The file will be in read-write mode, but GDAL won't be able to extend it as the allocated memory will be tied to the Buffer object. Use gdal.vsimem.copy to create an extendable copy.

Parameters:

  • data Buffer

    A binary buffer containing the file data

  • filename String

    A file name beginning with /vsimem/