<div dir="ltr">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. <div><br></div><div>Is there anything especially wrong with the following?   It's essentially the same as the answer here: </div><div><br></div><div><a href="https://lists.osgeo.org/pipermail/gdal-dev/2016-August/045030.html">https://lists.osgeo.org/pipermail/gdal-dev/2016-August/045030.html</a><br></div><div> </div><div>   (I know it needs error checks, I just mean the bare style of how to get the task done). <br></div><div><br></div><div>temp_name = "/vsimem/some.tif"<br>from osgeo import gdal<br>gdal.UseExceptions()<br><br>## we do something with vrt<br>dsn = "vrt:///vsicurl/<a href="https://github.com/cran/rgl/raw/master/inst/textures/worldsmall.png?a_ullr=-180,90,180,-90&expand=rgb">https://github.com/cran/rgl/raw/master/inst/textures/worldsmall.png?a_ullr=-180,90,180,-90&expand=rgb</a>"<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</div><div><br></div><div>## 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></div><div><div><br></div><div>Cheers, Mike</div><div><br></div><div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Michael Sumner<br>Software and Database Engineer<br>Australian Antarctic Division<br>Hobart, Australia<br>e-mail: <a href="mailto:mdsumner@gmail.com" target="_blank">mdsumner@gmail.com</a></div></div></div></div>