def vsifile_generic(filename): fp = gdal.VSIFOpenL(filename, 'wb+') gdal.VSIFWriteL('0123456789', 1, 10, fp) gdal.VSIFTruncateL(fp, 5) if gdal.VSIFTellL(fp) != 10: gdaltest.post_reason('failure') return 'fail' gdal.VSIFSeekL(fp, 0, 2) if gdal.VSIFTellL(fp) != 5: gdaltest.post_reason('failure') return 'fail' gdal.VSIFWriteL('XX', 1, 2, fp) gdal.VSIFCloseL(fp) statBuf = gdal.VSIStatL( filename, gdal.VSI_STAT_EXISTS_FLAG | gdal.VSI_STAT_NATURE_FLAG | gdal.VSI_STAT_SIZE_FLAG) if statBuf.size != 7: gdaltest.post_reason('failure') print(statBuf.size) return 'fail' fp = gdal.VSIFOpenL(filename, 'rb') buf = gdal.VSIFReadL(1, 7, fp) gdal.VSIFCloseL(fp) if buf.decode('ascii') != '01234XX': gdaltest.post_reason('failure') return 'fail' gdal.Unlink(filename) statBuf = gdal.VSIStatL(filename, gdal.VSI_STAT_EXISTS_FLAG) if statBuf is not None: gdaltest.post_reason('failure') return 'fail' return 'success'
def vsifile_3(): if (gdaltest.filesystem_supports_sparse_files('tmp') == False): return 'skip' filename = 'tmp/vsifile_3' fp = gdal.VSIFOpenL(filename, 'wb+') gdal.VSIFTruncateL(fp, 10 * 1024 * 1024 * 1024) gdal.VSIFSeekL(fp, 0, 2) pos = gdal.VSIFTellL(fp) if pos != 10 * 1024 * 1024 * 1024: gdaltest.post_reason('failure') gdal.VSIFCloseL(fp) gdal.Unlink(filename) print(pos) return 'fail' gdal.VSIFSeekL(fp, 0, 0) gdal.VSIFSeekL(fp, pos, 0) pos = gdal.VSIFTellL(fp) if pos != 10 * 1024 * 1024 * 1024: gdaltest.post_reason('failure') gdal.VSIFCloseL(fp) gdal.Unlink(filename) print(pos) return 'fail' gdal.VSIFCloseL(fp) statBuf = gdal.VSIStatL( filename, gdal.VSI_STAT_EXISTS_FLAG | gdal.VSI_STAT_NATURE_FLAG | gdal.VSI_STAT_SIZE_FLAG) gdal.Unlink(filename) if statBuf.size != 10 * 1024 * 1024 * 1024: gdaltest.post_reason('failure') print(statBuf.size) return 'fail' return 'success'