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
autotest: Add a VSIFile wrapper class #8222
base: master
Are you sure you want to change the base?
Conversation
swig/include/python/gdal_python.i
Outdated
self._binary = "b" in mode | ||
self._encoding = encoding | ||
|
||
self._fp = VSIFOpenL(self._path, self._mode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably throw an exception is None is returned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, also switched to VSIFOpenExL
to capture the error message
swig/include/python/gdal_python.i
Outdated
return self | ||
|
||
def __next__(self): | ||
chunk_size = 1024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably that CPLReadLineL() could be used to avoid this reimplementatoin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
If it's helpful, here's an implementation we have been using at Koordinates for a while, with a set of tests: feel free to crib anything that's useful. I've licensed it as MIT. Any questions most welcome. https://gist.github.com/rcoup/5f4b49149ca26084eed4dccfd1b12895
|
Fantastic, thank you! |
I have not forgotten about this. I'm leaning towards moving it to |
The GDAL project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 28 days and is being automatically marked as "stale". If you think this pull request should be merged, please check
|
8532886
to
6a5158c
Compare
gdal.VSIFWriteL(x, 1, len(x), self._fp) | ||
|
||
def seek(self, offset, whence=0): | ||
gdal.VSIFSeekL(self._fp, offset, whence) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to be careful here. Due to VSIFSeekL() taking only unsigned offsets, negative seeking with SEEK_CUR must be emulated doing VSIFSeekL(fp, VSIFTellL(fp) + offset, SEEK_SET)
What does this PR do?
This PR adds a
gdal.vsi_open()
function that returns a file-like object, allowing virtual files to be used as "regular" Python files in some cases. For example, a zipped CSV can be read using the Pythoncsv
module:Still need to correctly handle different linebreak/OS combinations, ensure errors are raised when accessing a closed file, handle append mode (or raise error), and probably other things.
What are related issues/pull requests?
Tasklist