Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get vsimem file buffer #85

Open
wandergis opened this issue May 23, 2023 · 3 comments
Open

Unable to get vsimem file buffer #85

wandergis opened this issue May 23, 2023 · 3 comments

Comments

@wandergis
Copy link

like python gdal binding lib:

from osgeo import gdal

filep = "/vsimem/foo.tif"

# get the file size
stat = gdal.VSIStatL(filep, gdal.VSI_STAT_SIZE_FLAG)

# open file
vsifile = gdal.VSIFOpenL(filep, 'r')

# read entire contents
vsimem_content = gdal.VSIFReadL(1, stat.size, vsifile)
@mmomtchev
Copy link
Owner

There are no file operations in Node.js, however you can still retrieve the file in a Buffer by calling vsimem.release:
https://mmomtchev.github.io/node-gdal-async/#vsimem

Here is an extract from the unit test:

// Create an in-memory dataset
const size = 64
const ds = gdal.open('/vsimem/temp1.tiff', 'w', 'GTiff', size, size, 1, gdal.GDT_Byte)
const data = new Uint8Array(size * size)
for (let i = 0; i < data.length; i ++) data[i] = Math.round(Math.random() * 256)
ds.bands.get(1).pixels.write(0, 0, ds.rasterSize.x, ds.rasterSize.y, data)
ds.close()

// Happens here
const buffer = gdal.vsimem.release('/vsimem/temp1.tiff')
assert.instanceOf(buffer, Buffer)

@zy6p
Copy link

zy6p commented May 25, 2023

What about the file header? Or doesn't exist.

@mmomtchev
Copy link
Owner

What do you mean by the file header?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants