<html><head></head><body dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="ApplePlainTextBody"><div class="ApplePlainTextBody">If using Numpy ReadAsArray maybe your friend<br><br><blockquote type="cite">On Apr 14, 2024, at 7:48 PM, Michael Sumner via gdal-dev <gdal-dev@lists.osgeo.org> wrote:<br><br>Hi, I'm getting some pushback on my code style. I just want the raw bytes in-memory of a file in Python, for a manageable tiny dataset. <br><br>Is there anything especially wrong with the following? It's essentially the same as the answer here: <br><br>https://lists.osgeo.org/pipermail/gdal-dev/2016-August/045030.html<br><br> (I know it needs error checks, I just mean the bare style of how to get the task done). <br><br>temp_name = "/vsimem/some.tif"<br>from osgeo import gdal<br>gdal.UseExceptions()<br><br>## we do something with vrt<br>dsn = "vrt:///vsicurl/https://github.com/cran/rgl/raw/master/inst/textures/worldsmall.png?a_ullr=-180,90,180,-90&expand=rgb"<br>ds = gdal.Open(dsn)<br>## write to tif format, but using MEM<br>gdal.Translate(temp_name, ds)<br><br>## now obtain those bytes from the GDAL virtual file<br>f = gdal.VSIFOpenL(temp_name, 'rb')<br>gdal.VSIFSeekL(f, 0, 2) # end<br>size = gdal.VSIFTellL(f)<br>gdal.VSIFSeekL(f, 0, 0) # begin<br><br>## the desired result is this<br>data = gdal.VSIFReadL(1, size, f)<br><br>## and clean up<br>gdal.VSIFCloseL(f)<br>gdal.Unlink(temp_name)<br><br>Cheers, Mike<br><br><br><br>-- <br>Michael Sumner<br>Software and Database Engineer<br>Australian Antarctic Division<br>Hobart, Australia<br>e-mail: mdsumner@gmail.com<br>_______________________________________________<br>gdal-dev mailing list<br>gdal-dev@lists.osgeo.org<br>https://lists.osgeo.org/mailman/listinfo/gdal-dev<br></blockquote><br></div></body></html>