@@ -2594,9 +2594,9 @@ def open(cls, fpath):
25942594
25952595
25962596# TODO: options to display as hex or decimal
2597- # >>> s = f.read(20 )
2597+ # >>> s = f.read(10 )
25982598# >>> s
2599- # b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ xc2\xea\x81\xb3\x14\x11\xcf\xbd
2599+ # b'\x00\x00\xc2\xea\x81\xb3\x14\x11\xcf\xbd
26002600@adapter_for ('_io.BufferedReader' )
26012601class BinaryFileAdapter (AbstractAdapter ):
26022602 def __init__ (self , data , attributes ):
@@ -3172,6 +3172,31 @@ def open(cls, fpath):
31723172 return duckdb .connect (fpath )
31733173
31743174
3175+ class CSVGZPathAdapater (CsvFileAdapter ):
3176+ @classmethod
3177+ def open (cls , fpath ):
3178+ import gzip
3179+ # not specifying an encoding is not an option because in that case
3180+ # we would get bytes and not str, which makes csv reader unhappy
3181+ return gzip .open (fpath , mode = 'rt' , encoding = 'utf-8' )
3182+
3183+ @property
3184+ def _binary_file (self ):
3185+ import gzip
3186+ return gzip .open (self .data .name , mode = 'rb' )
3187+
3188+
3189+ @path_adapter_for ('.gz' , 'gzip' )
3190+ def dispatch_gzip_path_adapter (gz_path ):
3191+ # strip .gz extension and dispatch to appropriate adapter
3192+ fpath = gz_path .with_name (gz_path .stem )
3193+ suffix = fpath .suffix .lower ()
3194+ if suffix == '.csv' :
3195+ return CSVGZPathAdapater
3196+ else :
3197+ return None
3198+
3199+
31753200@adapter_for ('zipfile.ZipFile' )
31763201class ZipFileAdapter (AbstractColumnarAdapter ):
31773202 def __init__ (self , data , attributes ):
@@ -3211,31 +3236,6 @@ def cell_activated(self, row_idx, column_idx):
32113236 # return self.data.open(info.filename)
32123237
32133238
3214- class CSVGZPathAdapater (CsvFileAdapter ):
3215- @classmethod
3216- def open (cls , fpath ):
3217- import gzip
3218- # not specifying an encoding is not an option because in that case
3219- # we would get bytes and not str, which makes csv reader unhappy
3220- return gzip .open (fpath , mode = 'rt' , encoding = 'utf-8' )
3221-
3222- @property
3223- def _binary_file (self ):
3224- import gzip
3225- return gzip .open (self .data .name , mode = 'rb' )
3226-
3227-
3228- @path_adapter_for ('.gz' , 'gzip' )
3229- def dispatch_gzip_path_adapter (gz_path ):
3230- # strip .gz extension and dispatch to appropriate adapter
3231- fpath = gz_path .with_name (gz_path .stem )
3232- suffix = fpath .suffix .lower ()
3233- if suffix == '.csv' :
3234- return CSVGZPathAdapater
3235- else :
3236- return None
3237-
3238-
32393239@path_adapter_for ('.zip' , 'zipfile' )
32403240class ZipPathAdapter (ZipFileAdapter ):
32413241 @classmethod
0 commit comments