File tree Expand file tree Collapse file tree 4 files changed +38
-1
lines changed
Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 3232 - uses : actions/setup-python@v2
3333 with :
3434 python-version : ${{ matrix.python }}
35- - run : pip install -e .[zstd]
35+ - run : pip install -e .[lz4, zstd]
3636 - run : python setup.py test
Original file line number Diff line number Diff line change 2525 'compression formats.' ,
2626 long_description = long_description ,
2727 extras_require = {
28+ 'lz4' : ['lz4 >= 2.2.1' ],
2829 'zstd' : ['zstandard >= 0.10.2' ]
2930 },
3031 python_requires = '>=3.4' ,
Original file line number Diff line number Diff line change 1+ from contextlib import contextmanager
2+ from tarfile import open as tarfile_open
3+
4+ try :
5+ import lz4 .frame as lz4
6+ except ImportError :
7+ lz4 = None
8+
9+
10+ class Lz4Tarfile :
11+ def __init__ (self , ** kwargs ):
12+ self .lz4_kwargs = kwargs
13+
14+ @contextmanager
15+ def read (self , path : str , mode : str ):
16+ with lz4 .LZ4FrameFile (path ) as lz4d :
17+ archive = tarfile_open (mode = mode , fileobj = lz4d , ** self .lz4_kwargs )
18+ try :
19+ yield archive
20+ finally :
21+ archive .close ()
22+
23+ @contextmanager
24+ def write (self , path : str , mode : str ):
25+ with lz4 .LZ4FrameFile (path , mode = mode [0 ]) as lz4c :
26+ archive = tarfile_open (mode = mode , fileobj = lz4c , ** self .lz4_kwargs )
27+ try :
28+ yield archive
29+ finally :
30+ archive .close ()
31+
32+
33+ if lz4 is None :
34+ Lz4Tarfile = None # noqa F811
Original file line number Diff line number Diff line change 22from tarfile import open as tarfile_open
33
44from xtarfile .zstd import ZstandardTarfile
5+ from xtarfile .lz4 import Lz4Tarfile
56
67
78_HANDLERS = {
89 'zstd' : ZstandardTarfile ,
910 'zst' : ZstandardTarfile ,
11+ 'lz4' : Lz4Tarfile ,
1012}
1113
1214_NATIVE_FORMATS = ('gz' , 'bz2' , 'xz' , 'tar' )
You can’t perform that action at this time.
0 commit comments