Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/__init__.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/__main__.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/base_events.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/base_futures.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/base_subprocess.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/base_tasks.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/constants.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/coroutines.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/events.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/exceptions.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/format_helpers.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/futures.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/graph.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/locks.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/log.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/mixins.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/proactor_events.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/protocols.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/queues.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/runners.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/selector_events.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/sslproto.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/staggered.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/streams.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/subprocess.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/taskgroups.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/tasks.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/threads.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/timeouts.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/tools.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/transports.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/trsock.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/unix_events.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/windows_events.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/windows_utils.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/collections/__pycache__/__init__.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/compression/__pycache__/__init__.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/compression/__pycache__/bz2.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/compression/__pycache__/gzip.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/compression/__pycache__/lzma.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/compression/__pycache__/zlib.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/compression/_common/__init__.py +0 -0
- micromamba_root/envs/hf_sync/Lib/compression/_common/__pycache__/__init__.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/compression/_common/__pycache__/_streams.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/compression/_common/_streams.py +162 -0
- micromamba_root/envs/hf_sync/Lib/compression/zstd/__init__.py +242 -0
- micromamba_root/envs/hf_sync/Lib/compression/zstd/__pycache__/__init__.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/compression/zstd/__pycache__/_zstdfile.cpython-314.pyc +0 -0
- micromamba_root/envs/hf_sync/Lib/compression/zstd/_zstdfile.py +345 -0
- micromamba_root/envs/hf_sync/Lib/concurrent/__pycache__/__init__.cpython-314.pyc +0 -0
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/__init__.cpython-314.pyc
ADDED
|
Binary file (3.11 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/__main__.cpython-314.pyc
ADDED
|
Binary file (11 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/base_events.cpython-314.pyc
ADDED
|
Binary file (92.6 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/base_futures.cpython-314.pyc
ADDED
|
Binary file (3.22 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/base_subprocess.cpython-314.pyc
ADDED
|
Binary file (18.1 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/base_tasks.cpython-314.pyc
ADDED
|
Binary file (4.19 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/constants.cpython-314.pyc
ADDED
|
Binary file (975 Bytes). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/coroutines.cpython-314.pyc
ADDED
|
Binary file (4.46 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/events.cpython-314.pyc
ADDED
|
Binary file (37.7 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/exceptions.cpython-314.pyc
ADDED
|
Binary file (3.25 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/format_helpers.cpython-314.pyc
ADDED
|
Binary file (4.32 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/futures.cpython-314.pyc
ADDED
|
Binary file (19.2 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/graph.cpython-314.pyc
ADDED
|
Binary file (11.3 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/locks.cpython-314.pyc
ADDED
|
Binary file (28.8 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/log.cpython-314.pyc
ADDED
|
Binary file (260 Bytes). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/mixins.cpython-314.pyc
ADDED
|
Binary file (1.15 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/proactor_events.cpython-314.pyc
ADDED
|
Binary file (47.3 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/protocols.cpython-314.pyc
ADDED
|
Binary file (8.54 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/queues.cpython-314.pyc
ADDED
|
Binary file (14.7 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/runners.cpython-314.pyc
ADDED
|
Binary file (10.6 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/selector_events.cpython-314.pyc
ADDED
|
Binary file (66.5 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/sslproto.cpython-314.pyc
ADDED
|
Binary file (42.6 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/staggered.cpython-314.pyc
ADDED
|
Binary file (7.17 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/streams.cpython-314.pyc
ADDED
|
Binary file (34.8 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/subprocess.cpython-314.pyc
ADDED
|
Binary file (12.6 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/taskgroups.cpython-314.pyc
ADDED
|
Binary file (9.69 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/tasks.cpython-314.pyc
ADDED
|
Binary file (45.7 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/threads.cpython-314.pyc
ADDED
|
Binary file (1.22 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/timeouts.cpython-314.pyc
ADDED
|
Binary file (10.3 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/tools.cpython-314.pyc
ADDED
|
Binary file (15.8 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/transports.cpython-314.pyc
ADDED
|
Binary file (14 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/trsock.cpython-314.pyc
ADDED
|
Binary file (5.4 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/unix_events.cpython-314.pyc
ADDED
|
Binary file (48 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/windows_events.cpython-314.pyc
ADDED
|
Binary file (43 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/asyncio/__pycache__/windows_utils.cpython-314.pyc
ADDED
|
Binary file (8.17 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/collections/__pycache__/__init__.cpython-314.pyc
ADDED
|
Binary file (74.7 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/compression/__pycache__/__init__.cpython-314.pyc
ADDED
|
Binary file (126 Bytes). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/compression/__pycache__/bz2.cpython-314.pyc
ADDED
|
Binary file (204 Bytes). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/compression/__pycache__/gzip.cpython-314.pyc
ADDED
|
Binary file (206 Bytes). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/compression/__pycache__/lzma.cpython-314.pyc
ADDED
|
Binary file (206 Bytes). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/compression/__pycache__/zlib.cpython-314.pyc
ADDED
|
Binary file (206 Bytes). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/compression/_common/__init__.py
ADDED
|
File without changes
|
micromamba_root/envs/hf_sync/Lib/compression/_common/__pycache__/__init__.cpython-314.pyc
ADDED
|
Binary file (134 Bytes). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/compression/_common/__pycache__/_streams.cpython-314.pyc
ADDED
|
Binary file (7.79 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/compression/_common/_streams.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Internal classes used by compression modules"""
|
| 2 |
+
|
| 3 |
+
import io
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
BUFFER_SIZE = io.DEFAULT_BUFFER_SIZE # Compressed data read chunk size
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class BaseStream(io.BufferedIOBase):
|
| 10 |
+
"""Mode-checking helper functions."""
|
| 11 |
+
|
| 12 |
+
def _check_not_closed(self):
|
| 13 |
+
if self.closed:
|
| 14 |
+
raise ValueError("I/O operation on closed file")
|
| 15 |
+
|
| 16 |
+
def _check_can_read(self):
|
| 17 |
+
if not self.readable():
|
| 18 |
+
raise io.UnsupportedOperation("File not open for reading")
|
| 19 |
+
|
| 20 |
+
def _check_can_write(self):
|
| 21 |
+
if not self.writable():
|
| 22 |
+
raise io.UnsupportedOperation("File not open for writing")
|
| 23 |
+
|
| 24 |
+
def _check_can_seek(self):
|
| 25 |
+
if not self.readable():
|
| 26 |
+
raise io.UnsupportedOperation("Seeking is only supported "
|
| 27 |
+
"on files open for reading")
|
| 28 |
+
if not self.seekable():
|
| 29 |
+
raise io.UnsupportedOperation("The underlying file object "
|
| 30 |
+
"does not support seeking")
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class DecompressReader(io.RawIOBase):
|
| 34 |
+
"""Adapts the decompressor API to a RawIOBase reader API"""
|
| 35 |
+
|
| 36 |
+
def readable(self):
|
| 37 |
+
return True
|
| 38 |
+
|
| 39 |
+
def __init__(self, fp, decomp_factory, trailing_error=(), **decomp_args):
|
| 40 |
+
self._fp = fp
|
| 41 |
+
self._eof = False
|
| 42 |
+
self._pos = 0 # Current offset in decompressed stream
|
| 43 |
+
|
| 44 |
+
# Set to size of decompressed stream once it is known, for SEEK_END
|
| 45 |
+
self._size = -1
|
| 46 |
+
|
| 47 |
+
# Save the decompressor factory and arguments.
|
| 48 |
+
# If the file contains multiple compressed streams, each
|
| 49 |
+
# stream will need a separate decompressor object. A new decompressor
|
| 50 |
+
# object is also needed when implementing a backwards seek().
|
| 51 |
+
self._decomp_factory = decomp_factory
|
| 52 |
+
self._decomp_args = decomp_args
|
| 53 |
+
self._decompressor = self._decomp_factory(**self._decomp_args)
|
| 54 |
+
|
| 55 |
+
# Exception class to catch from decompressor signifying invalid
|
| 56 |
+
# trailing data to ignore
|
| 57 |
+
self._trailing_error = trailing_error
|
| 58 |
+
|
| 59 |
+
def close(self):
|
| 60 |
+
self._decompressor = None
|
| 61 |
+
return super().close()
|
| 62 |
+
|
| 63 |
+
def seekable(self):
|
| 64 |
+
return self._fp.seekable()
|
| 65 |
+
|
| 66 |
+
def readinto(self, b):
|
| 67 |
+
with memoryview(b) as view, view.cast("B") as byte_view:
|
| 68 |
+
data = self.read(len(byte_view))
|
| 69 |
+
byte_view[:len(data)] = data
|
| 70 |
+
return len(data)
|
| 71 |
+
|
| 72 |
+
def read(self, size=-1):
|
| 73 |
+
if size < 0:
|
| 74 |
+
return self.readall()
|
| 75 |
+
|
| 76 |
+
if not size or self._eof:
|
| 77 |
+
return b""
|
| 78 |
+
data = None # Default if EOF is encountered
|
| 79 |
+
# Depending on the input data, our call to the decompressor may not
|
| 80 |
+
# return any data. In this case, try again after reading another block.
|
| 81 |
+
while True:
|
| 82 |
+
if self._decompressor.eof:
|
| 83 |
+
rawblock = (self._decompressor.unused_data or
|
| 84 |
+
self._fp.read(BUFFER_SIZE))
|
| 85 |
+
if not rawblock:
|
| 86 |
+
break
|
| 87 |
+
# Continue to next stream.
|
| 88 |
+
self._decompressor = self._decomp_factory(
|
| 89 |
+
**self._decomp_args)
|
| 90 |
+
try:
|
| 91 |
+
data = self._decompressor.decompress(rawblock, size)
|
| 92 |
+
except self._trailing_error:
|
| 93 |
+
# Trailing data isn't a valid compressed stream; ignore it.
|
| 94 |
+
break
|
| 95 |
+
else:
|
| 96 |
+
if self._decompressor.needs_input:
|
| 97 |
+
rawblock = self._fp.read(BUFFER_SIZE)
|
| 98 |
+
if not rawblock:
|
| 99 |
+
raise EOFError("Compressed file ended before the "
|
| 100 |
+
"end-of-stream marker was reached")
|
| 101 |
+
else:
|
| 102 |
+
rawblock = b""
|
| 103 |
+
data = self._decompressor.decompress(rawblock, size)
|
| 104 |
+
if data:
|
| 105 |
+
break
|
| 106 |
+
if not data:
|
| 107 |
+
self._eof = True
|
| 108 |
+
self._size = self._pos
|
| 109 |
+
return b""
|
| 110 |
+
self._pos += len(data)
|
| 111 |
+
return data
|
| 112 |
+
|
| 113 |
+
def readall(self):
|
| 114 |
+
chunks = []
|
| 115 |
+
# sys.maxsize means the max length of output buffer is unlimited,
|
| 116 |
+
# so that the whole input buffer can be decompressed within one
|
| 117 |
+
# .decompress() call.
|
| 118 |
+
while data := self.read(sys.maxsize):
|
| 119 |
+
chunks.append(data)
|
| 120 |
+
|
| 121 |
+
return b"".join(chunks)
|
| 122 |
+
|
| 123 |
+
# Rewind the file to the beginning of the data stream.
|
| 124 |
+
def _rewind(self):
|
| 125 |
+
self._fp.seek(0)
|
| 126 |
+
self._eof = False
|
| 127 |
+
self._pos = 0
|
| 128 |
+
self._decompressor = self._decomp_factory(**self._decomp_args)
|
| 129 |
+
|
| 130 |
+
def seek(self, offset, whence=io.SEEK_SET):
|
| 131 |
+
# Recalculate offset as an absolute file position.
|
| 132 |
+
if whence == io.SEEK_SET:
|
| 133 |
+
pass
|
| 134 |
+
elif whence == io.SEEK_CUR:
|
| 135 |
+
offset = self._pos + offset
|
| 136 |
+
elif whence == io.SEEK_END:
|
| 137 |
+
# Seeking relative to EOF - we need to know the file's size.
|
| 138 |
+
if self._size < 0:
|
| 139 |
+
while self.read(io.DEFAULT_BUFFER_SIZE):
|
| 140 |
+
pass
|
| 141 |
+
offset = self._size + offset
|
| 142 |
+
else:
|
| 143 |
+
raise ValueError("Invalid value for whence: {}".format(whence))
|
| 144 |
+
|
| 145 |
+
# Make it so that offset is the number of bytes to skip forward.
|
| 146 |
+
if offset < self._pos:
|
| 147 |
+
self._rewind()
|
| 148 |
+
else:
|
| 149 |
+
offset -= self._pos
|
| 150 |
+
|
| 151 |
+
# Read and discard data until we reach the desired position.
|
| 152 |
+
while offset > 0:
|
| 153 |
+
data = self.read(min(io.DEFAULT_BUFFER_SIZE, offset))
|
| 154 |
+
if not data:
|
| 155 |
+
break
|
| 156 |
+
offset -= len(data)
|
| 157 |
+
|
| 158 |
+
return self._pos
|
| 159 |
+
|
| 160 |
+
def tell(self):
|
| 161 |
+
"""Return the current file position."""
|
| 162 |
+
return self._pos
|
micromamba_root/envs/hf_sync/Lib/compression/zstd/__init__.py
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Python bindings to the Zstandard (zstd) compression library (RFC-8878)."""
|
| 2 |
+
|
| 3 |
+
__all__ = (
|
| 4 |
+
# compression.zstd
|
| 5 |
+
'COMPRESSION_LEVEL_DEFAULT',
|
| 6 |
+
'compress',
|
| 7 |
+
'CompressionParameter',
|
| 8 |
+
'decompress',
|
| 9 |
+
'DecompressionParameter',
|
| 10 |
+
'finalize_dict',
|
| 11 |
+
'get_frame_info',
|
| 12 |
+
'Strategy',
|
| 13 |
+
'train_dict',
|
| 14 |
+
|
| 15 |
+
# compression.zstd._zstdfile
|
| 16 |
+
'open',
|
| 17 |
+
'ZstdFile',
|
| 18 |
+
|
| 19 |
+
# _zstd
|
| 20 |
+
'get_frame_size',
|
| 21 |
+
'zstd_version',
|
| 22 |
+
'zstd_version_info',
|
| 23 |
+
'ZstdCompressor',
|
| 24 |
+
'ZstdDecompressor',
|
| 25 |
+
'ZstdDict',
|
| 26 |
+
'ZstdError',
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
import _zstd
|
| 30 |
+
import enum
|
| 31 |
+
from _zstd import (ZstdCompressor, ZstdDecompressor, ZstdDict, ZstdError,
|
| 32 |
+
get_frame_size, zstd_version)
|
| 33 |
+
from compression.zstd._zstdfile import ZstdFile, open, _nbytes
|
| 34 |
+
|
| 35 |
+
# zstd_version_number is (MAJOR * 100 * 100 + MINOR * 100 + RELEASE)
|
| 36 |
+
zstd_version_info = (*divmod(_zstd.zstd_version_number // 100, 100),
|
| 37 |
+
_zstd.zstd_version_number % 100)
|
| 38 |
+
"""Version number of the runtime zstd library as a tuple of integers."""
|
| 39 |
+
|
| 40 |
+
COMPRESSION_LEVEL_DEFAULT = _zstd.ZSTD_CLEVEL_DEFAULT
|
| 41 |
+
"""The default compression level for Zstandard, currently '3'."""
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class FrameInfo:
|
| 45 |
+
"""Information about a Zstandard frame."""
|
| 46 |
+
|
| 47 |
+
__slots__ = 'decompressed_size', 'dictionary_id'
|
| 48 |
+
|
| 49 |
+
def __init__(self, decompressed_size, dictionary_id):
|
| 50 |
+
super().__setattr__('decompressed_size', decompressed_size)
|
| 51 |
+
super().__setattr__('dictionary_id', dictionary_id)
|
| 52 |
+
|
| 53 |
+
def __repr__(self):
|
| 54 |
+
return (f'FrameInfo(decompressed_size={self.decompressed_size}, '
|
| 55 |
+
f'dictionary_id={self.dictionary_id})')
|
| 56 |
+
|
| 57 |
+
def __setattr__(self, name, _):
|
| 58 |
+
raise AttributeError(f"can't set attribute {name!r}")
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def get_frame_info(frame_buffer):
|
| 62 |
+
"""Get Zstandard frame information from a frame header.
|
| 63 |
+
|
| 64 |
+
*frame_buffer* is a bytes-like object. It should start from the beginning
|
| 65 |
+
of a frame, and needs to include at least the frame header (6 to 18 bytes).
|
| 66 |
+
|
| 67 |
+
The returned FrameInfo object has two attributes.
|
| 68 |
+
'decompressed_size' is the size in bytes of the data in the frame when
|
| 69 |
+
decompressed, or None when the decompressed size is unknown.
|
| 70 |
+
'dictionary_id' is an int in the range (0, 2**32). The special value 0
|
| 71 |
+
means that the dictionary ID was not recorded in the frame header,
|
| 72 |
+
the frame may or may not need a dictionary to be decoded,
|
| 73 |
+
and the ID of such a dictionary is not specified.
|
| 74 |
+
"""
|
| 75 |
+
return FrameInfo(*_zstd.get_frame_info(frame_buffer))
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def train_dict(samples, dict_size):
|
| 79 |
+
"""Return a ZstdDict representing a trained Zstandard dictionary.
|
| 80 |
+
|
| 81 |
+
*samples* is an iterable of samples, where a sample is a bytes-like
|
| 82 |
+
object representing a file.
|
| 83 |
+
|
| 84 |
+
*dict_size* is the dictionary's maximum size, in bytes.
|
| 85 |
+
"""
|
| 86 |
+
if not isinstance(dict_size, int):
|
| 87 |
+
ds_cls = type(dict_size).__qualname__
|
| 88 |
+
raise TypeError(f'dict_size must be an int object, not {ds_cls!r}.')
|
| 89 |
+
|
| 90 |
+
samples = tuple(samples)
|
| 91 |
+
chunks = b''.join(samples)
|
| 92 |
+
chunk_sizes = tuple(_nbytes(sample) for sample in samples)
|
| 93 |
+
if not chunks:
|
| 94 |
+
raise ValueError("samples contained no data; can't train dictionary.")
|
| 95 |
+
dict_content = _zstd.train_dict(chunks, chunk_sizes, dict_size)
|
| 96 |
+
return ZstdDict(dict_content)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def finalize_dict(zstd_dict, /, samples, dict_size, level):
|
| 100 |
+
"""Return a ZstdDict representing a finalized Zstandard dictionary.
|
| 101 |
+
|
| 102 |
+
Given a custom content as a basis for dictionary, and a set of samples,
|
| 103 |
+
finalize *zstd_dict* by adding headers and statistics according to the
|
| 104 |
+
Zstandard dictionary format.
|
| 105 |
+
|
| 106 |
+
You may compose an effective dictionary content by hand, which is used as
|
| 107 |
+
basis dictionary, and use some samples to finalize a dictionary. The basis
|
| 108 |
+
dictionary may be a "raw content" dictionary. See *is_raw* in ZstdDict.
|
| 109 |
+
|
| 110 |
+
*samples* is an iterable of samples, where a sample is a bytes-like object
|
| 111 |
+
representing a file.
|
| 112 |
+
*dict_size* is the dictionary's maximum size, in bytes.
|
| 113 |
+
*level* is the expected compression level. The statistics for each
|
| 114 |
+
compression level differ, so tuning the dictionary to the compression level
|
| 115 |
+
can provide improvements.
|
| 116 |
+
"""
|
| 117 |
+
|
| 118 |
+
if not isinstance(zstd_dict, ZstdDict):
|
| 119 |
+
raise TypeError('zstd_dict argument should be a ZstdDict object.')
|
| 120 |
+
if not isinstance(dict_size, int):
|
| 121 |
+
raise TypeError('dict_size argument should be an int object.')
|
| 122 |
+
if not isinstance(level, int):
|
| 123 |
+
raise TypeError('level argument should be an int object.')
|
| 124 |
+
|
| 125 |
+
samples = tuple(samples)
|
| 126 |
+
chunks = b''.join(samples)
|
| 127 |
+
chunk_sizes = tuple(_nbytes(sample) for sample in samples)
|
| 128 |
+
if not chunks:
|
| 129 |
+
raise ValueError("The samples are empty content, can't finalize the "
|
| 130 |
+
"dictionary.")
|
| 131 |
+
dict_content = _zstd.finalize_dict(zstd_dict.dict_content, chunks,
|
| 132 |
+
chunk_sizes, dict_size, level)
|
| 133 |
+
return ZstdDict(dict_content)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def compress(data, level=None, options=None, zstd_dict=None):
|
| 137 |
+
"""Return Zstandard compressed *data* as bytes.
|
| 138 |
+
|
| 139 |
+
*level* is an int specifying the compression level to use, defaulting to
|
| 140 |
+
COMPRESSION_LEVEL_DEFAULT ('3').
|
| 141 |
+
*options* is a dict object that contains advanced compression
|
| 142 |
+
parameters. See CompressionParameter for more on options.
|
| 143 |
+
*zstd_dict* is a ZstdDict object, a pre-trained Zstandard dictionary. See
|
| 144 |
+
the function train_dict for how to train a ZstdDict on sample data.
|
| 145 |
+
|
| 146 |
+
For incremental compression, use a ZstdCompressor instead.
|
| 147 |
+
"""
|
| 148 |
+
comp = ZstdCompressor(level=level, options=options, zstd_dict=zstd_dict)
|
| 149 |
+
return comp.compress(data, mode=ZstdCompressor.FLUSH_FRAME)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def decompress(data, zstd_dict=None, options=None):
|
| 153 |
+
"""Decompress one or more frames of Zstandard compressed *data*.
|
| 154 |
+
|
| 155 |
+
*zstd_dict* is a ZstdDict object, a pre-trained Zstandard dictionary. See
|
| 156 |
+
the function train_dict for how to train a ZstdDict on sample data.
|
| 157 |
+
*options* is a dict object that contains advanced compression
|
| 158 |
+
parameters. See DecompressionParameter for more on options.
|
| 159 |
+
|
| 160 |
+
For incremental decompression, use a ZstdDecompressor instead.
|
| 161 |
+
"""
|
| 162 |
+
results = []
|
| 163 |
+
while True:
|
| 164 |
+
decomp = ZstdDecompressor(options=options, zstd_dict=zstd_dict)
|
| 165 |
+
results.append(decomp.decompress(data))
|
| 166 |
+
if not decomp.eof:
|
| 167 |
+
raise ZstdError('Compressed data ended before the '
|
| 168 |
+
'end-of-stream marker was reached')
|
| 169 |
+
data = decomp.unused_data
|
| 170 |
+
if not data:
|
| 171 |
+
break
|
| 172 |
+
return b''.join(results)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
class CompressionParameter(enum.IntEnum):
|
| 176 |
+
"""Compression parameters."""
|
| 177 |
+
|
| 178 |
+
compression_level = _zstd.ZSTD_c_compressionLevel
|
| 179 |
+
window_log = _zstd.ZSTD_c_windowLog
|
| 180 |
+
hash_log = _zstd.ZSTD_c_hashLog
|
| 181 |
+
chain_log = _zstd.ZSTD_c_chainLog
|
| 182 |
+
search_log = _zstd.ZSTD_c_searchLog
|
| 183 |
+
min_match = _zstd.ZSTD_c_minMatch
|
| 184 |
+
target_length = _zstd.ZSTD_c_targetLength
|
| 185 |
+
strategy = _zstd.ZSTD_c_strategy
|
| 186 |
+
|
| 187 |
+
enable_long_distance_matching = _zstd.ZSTD_c_enableLongDistanceMatching
|
| 188 |
+
ldm_hash_log = _zstd.ZSTD_c_ldmHashLog
|
| 189 |
+
ldm_min_match = _zstd.ZSTD_c_ldmMinMatch
|
| 190 |
+
ldm_bucket_size_log = _zstd.ZSTD_c_ldmBucketSizeLog
|
| 191 |
+
ldm_hash_rate_log = _zstd.ZSTD_c_ldmHashRateLog
|
| 192 |
+
|
| 193 |
+
content_size_flag = _zstd.ZSTD_c_contentSizeFlag
|
| 194 |
+
checksum_flag = _zstd.ZSTD_c_checksumFlag
|
| 195 |
+
dict_id_flag = _zstd.ZSTD_c_dictIDFlag
|
| 196 |
+
|
| 197 |
+
nb_workers = _zstd.ZSTD_c_nbWorkers
|
| 198 |
+
job_size = _zstd.ZSTD_c_jobSize
|
| 199 |
+
overlap_log = _zstd.ZSTD_c_overlapLog
|
| 200 |
+
|
| 201 |
+
def bounds(self):
|
| 202 |
+
"""Return the (lower, upper) int bounds of a compression parameter.
|
| 203 |
+
|
| 204 |
+
Both the lower and upper bounds are inclusive.
|
| 205 |
+
"""
|
| 206 |
+
return _zstd.get_param_bounds(self.value, is_compress=True)
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
class DecompressionParameter(enum.IntEnum):
|
| 210 |
+
"""Decompression parameters."""
|
| 211 |
+
|
| 212 |
+
window_log_max = _zstd.ZSTD_d_windowLogMax
|
| 213 |
+
|
| 214 |
+
def bounds(self):
|
| 215 |
+
"""Return the (lower, upper) int bounds of a decompression parameter.
|
| 216 |
+
|
| 217 |
+
Both the lower and upper bounds are inclusive.
|
| 218 |
+
"""
|
| 219 |
+
return _zstd.get_param_bounds(self.value, is_compress=False)
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
class Strategy(enum.IntEnum):
|
| 223 |
+
"""Compression strategies, listed from fastest to strongest.
|
| 224 |
+
|
| 225 |
+
Note that new strategies might be added in the future.
|
| 226 |
+
Only the order (from fast to strong) is guaranteed,
|
| 227 |
+
the numeric value might change.
|
| 228 |
+
"""
|
| 229 |
+
|
| 230 |
+
fast = _zstd.ZSTD_fast
|
| 231 |
+
dfast = _zstd.ZSTD_dfast
|
| 232 |
+
greedy = _zstd.ZSTD_greedy
|
| 233 |
+
lazy = _zstd.ZSTD_lazy
|
| 234 |
+
lazy2 = _zstd.ZSTD_lazy2
|
| 235 |
+
btlazy2 = _zstd.ZSTD_btlazy2
|
| 236 |
+
btopt = _zstd.ZSTD_btopt
|
| 237 |
+
btultra = _zstd.ZSTD_btultra
|
| 238 |
+
btultra2 = _zstd.ZSTD_btultra2
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
# Check validity of the CompressionParameter & DecompressionParameter types
|
| 242 |
+
_zstd.set_parameter_types(CompressionParameter, DecompressionParameter)
|
micromamba_root/envs/hf_sync/Lib/compression/zstd/__pycache__/__init__.cpython-314.pyc
ADDED
|
Binary file (11.7 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/compression/zstd/__pycache__/_zstdfile.cpython-314.pyc
ADDED
|
Binary file (15.7 kB). View file
|
|
|
micromamba_root/envs/hf_sync/Lib/compression/zstd/_zstdfile.py
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
from os import PathLike
|
| 3 |
+
from _zstd import ZstdCompressor, ZstdDecompressor, ZSTD_DStreamOutSize
|
| 4 |
+
from compression._common import _streams
|
| 5 |
+
|
| 6 |
+
__all__ = ('ZstdFile', 'open')
|
| 7 |
+
|
| 8 |
+
_MODE_CLOSED = 0
|
| 9 |
+
_MODE_READ = 1
|
| 10 |
+
_MODE_WRITE = 2
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def _nbytes(dat, /):
|
| 14 |
+
if isinstance(dat, (bytes, bytearray)):
|
| 15 |
+
return len(dat)
|
| 16 |
+
with memoryview(dat) as mv:
|
| 17 |
+
return mv.nbytes
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class ZstdFile(_streams.BaseStream):
|
| 21 |
+
"""A file-like object providing transparent Zstandard (de)compression.
|
| 22 |
+
|
| 23 |
+
A ZstdFile can act as a wrapper for an existing file object, or refer
|
| 24 |
+
directly to a named file on disk.
|
| 25 |
+
|
| 26 |
+
ZstdFile provides a *binary* file interface. Data is read and returned as
|
| 27 |
+
bytes, and may only be written to objects that support the Buffer Protocol.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
FLUSH_BLOCK = ZstdCompressor.FLUSH_BLOCK
|
| 31 |
+
FLUSH_FRAME = ZstdCompressor.FLUSH_FRAME
|
| 32 |
+
|
| 33 |
+
def __init__(self, file, /, mode='r', *,
|
| 34 |
+
level=None, options=None, zstd_dict=None):
|
| 35 |
+
"""Open a Zstandard compressed file in binary mode.
|
| 36 |
+
|
| 37 |
+
*file* can be either an file-like object, or a file name to open.
|
| 38 |
+
|
| 39 |
+
*mode* can be 'r' for reading (default), 'w' for (over)writing, 'x' for
|
| 40 |
+
creating exclusively, or 'a' for appending. These can equivalently be
|
| 41 |
+
given as 'rb', 'wb', 'xb' and 'ab' respectively.
|
| 42 |
+
|
| 43 |
+
*level* is an optional int specifying the compression level to use,
|
| 44 |
+
or COMPRESSION_LEVEL_DEFAULT if not given.
|
| 45 |
+
|
| 46 |
+
*options* is an optional dict for advanced compression parameters.
|
| 47 |
+
See CompressionParameter and DecompressionParameter for the possible
|
| 48 |
+
options.
|
| 49 |
+
|
| 50 |
+
*zstd_dict* is an optional ZstdDict object, a pre-trained Zstandard
|
| 51 |
+
dictionary. See train_dict() to train ZstdDict on sample data.
|
| 52 |
+
"""
|
| 53 |
+
self._fp = None
|
| 54 |
+
self._close_fp = False
|
| 55 |
+
self._mode = _MODE_CLOSED
|
| 56 |
+
self._buffer = None
|
| 57 |
+
|
| 58 |
+
if not isinstance(mode, str):
|
| 59 |
+
raise ValueError('mode must be a str')
|
| 60 |
+
if options is not None and not isinstance(options, dict):
|
| 61 |
+
raise TypeError('options must be a dict or None')
|
| 62 |
+
mode = mode.removesuffix('b') # handle rb, wb, xb, ab
|
| 63 |
+
if mode == 'r':
|
| 64 |
+
if level is not None:
|
| 65 |
+
raise TypeError('level is illegal in read mode')
|
| 66 |
+
self._mode = _MODE_READ
|
| 67 |
+
elif mode in {'w', 'a', 'x'}:
|
| 68 |
+
if level is not None and not isinstance(level, int):
|
| 69 |
+
raise TypeError('level must be int or None')
|
| 70 |
+
self._mode = _MODE_WRITE
|
| 71 |
+
self._compressor = ZstdCompressor(level=level, options=options,
|
| 72 |
+
zstd_dict=zstd_dict)
|
| 73 |
+
self._pos = 0
|
| 74 |
+
else:
|
| 75 |
+
raise ValueError(f'Invalid mode: {mode!r}')
|
| 76 |
+
|
| 77 |
+
if isinstance(file, (str, bytes, PathLike)):
|
| 78 |
+
self._fp = io.open(file, f'{mode}b')
|
| 79 |
+
self._close_fp = True
|
| 80 |
+
elif ((mode == 'r' and hasattr(file, 'read'))
|
| 81 |
+
or (mode != 'r' and hasattr(file, 'write'))):
|
| 82 |
+
self._fp = file
|
| 83 |
+
else:
|
| 84 |
+
raise TypeError('file must be a file-like object '
|
| 85 |
+
'or a str, bytes, or PathLike object')
|
| 86 |
+
|
| 87 |
+
if self._mode == _MODE_READ:
|
| 88 |
+
raw = _streams.DecompressReader(
|
| 89 |
+
self._fp,
|
| 90 |
+
ZstdDecompressor,
|
| 91 |
+
zstd_dict=zstd_dict,
|
| 92 |
+
options=options,
|
| 93 |
+
)
|
| 94 |
+
self._buffer = io.BufferedReader(raw)
|
| 95 |
+
|
| 96 |
+
def close(self):
|
| 97 |
+
"""Flush and close the file.
|
| 98 |
+
|
| 99 |
+
May be called multiple times. Once the file has been closed,
|
| 100 |
+
any other operation on it will raise ValueError.
|
| 101 |
+
"""
|
| 102 |
+
if self._fp is None:
|
| 103 |
+
return
|
| 104 |
+
try:
|
| 105 |
+
if self._mode == _MODE_READ:
|
| 106 |
+
if getattr(self, '_buffer', None):
|
| 107 |
+
self._buffer.close()
|
| 108 |
+
self._buffer = None
|
| 109 |
+
elif self._mode == _MODE_WRITE:
|
| 110 |
+
self.flush(self.FLUSH_FRAME)
|
| 111 |
+
self._compressor = None
|
| 112 |
+
finally:
|
| 113 |
+
self._mode = _MODE_CLOSED
|
| 114 |
+
try:
|
| 115 |
+
if self._close_fp:
|
| 116 |
+
self._fp.close()
|
| 117 |
+
finally:
|
| 118 |
+
self._fp = None
|
| 119 |
+
self._close_fp = False
|
| 120 |
+
|
| 121 |
+
def write(self, data, /):
|
| 122 |
+
"""Write a bytes-like object *data* to the file.
|
| 123 |
+
|
| 124 |
+
Returns the number of uncompressed bytes written, which is
|
| 125 |
+
always the length of data in bytes. Note that due to buffering,
|
| 126 |
+
the file on disk may not reflect the data written until .flush()
|
| 127 |
+
or .close() is called.
|
| 128 |
+
"""
|
| 129 |
+
self._check_can_write()
|
| 130 |
+
|
| 131 |
+
length = _nbytes(data)
|
| 132 |
+
|
| 133 |
+
compressed = self._compressor.compress(data)
|
| 134 |
+
self._fp.write(compressed)
|
| 135 |
+
self._pos += length
|
| 136 |
+
return length
|
| 137 |
+
|
| 138 |
+
def flush(self, mode=FLUSH_BLOCK):
|
| 139 |
+
"""Flush remaining data to the underlying stream.
|
| 140 |
+
|
| 141 |
+
The mode argument can be FLUSH_BLOCK or FLUSH_FRAME. Abuse of this
|
| 142 |
+
method will reduce compression ratio, use it only when necessary.
|
| 143 |
+
|
| 144 |
+
If the program is interrupted afterwards, all data can be recovered.
|
| 145 |
+
To ensure saving to disk, also need to use os.fsync(fd).
|
| 146 |
+
|
| 147 |
+
This method does nothing in reading mode.
|
| 148 |
+
"""
|
| 149 |
+
if self._mode == _MODE_READ:
|
| 150 |
+
return
|
| 151 |
+
self._check_not_closed()
|
| 152 |
+
if mode not in {self.FLUSH_BLOCK, self.FLUSH_FRAME}:
|
| 153 |
+
raise ValueError('Invalid mode argument, expected either '
|
| 154 |
+
'ZstdFile.FLUSH_FRAME or '
|
| 155 |
+
'ZstdFile.FLUSH_BLOCK')
|
| 156 |
+
if self._compressor.last_mode == mode:
|
| 157 |
+
return
|
| 158 |
+
# Flush zstd block/frame, and write.
|
| 159 |
+
data = self._compressor.flush(mode)
|
| 160 |
+
self._fp.write(data)
|
| 161 |
+
if hasattr(self._fp, 'flush'):
|
| 162 |
+
self._fp.flush()
|
| 163 |
+
|
| 164 |
+
def read(self, size=-1):
|
| 165 |
+
"""Read up to size uncompressed bytes from the file.
|
| 166 |
+
|
| 167 |
+
If size is negative or omitted, read until EOF is reached.
|
| 168 |
+
Returns b'' if the file is already at EOF.
|
| 169 |
+
"""
|
| 170 |
+
if size is None:
|
| 171 |
+
size = -1
|
| 172 |
+
self._check_can_read()
|
| 173 |
+
return self._buffer.read(size)
|
| 174 |
+
|
| 175 |
+
def read1(self, size=-1):
|
| 176 |
+
"""Read up to size uncompressed bytes, while trying to avoid
|
| 177 |
+
making multiple reads from the underlying stream. Reads up to a
|
| 178 |
+
buffer's worth of data if size is negative.
|
| 179 |
+
|
| 180 |
+
Returns b'' if the file is at EOF.
|
| 181 |
+
"""
|
| 182 |
+
self._check_can_read()
|
| 183 |
+
if size < 0:
|
| 184 |
+
# Note this should *not* be io.DEFAULT_BUFFER_SIZE.
|
| 185 |
+
# ZSTD_DStreamOutSize is the minimum amount to read guaranteeing
|
| 186 |
+
# a full block is read.
|
| 187 |
+
size = ZSTD_DStreamOutSize
|
| 188 |
+
return self._buffer.read1(size)
|
| 189 |
+
|
| 190 |
+
def readinto(self, b):
|
| 191 |
+
"""Read bytes into b.
|
| 192 |
+
|
| 193 |
+
Returns the number of bytes read (0 for EOF).
|
| 194 |
+
"""
|
| 195 |
+
self._check_can_read()
|
| 196 |
+
return self._buffer.readinto(b)
|
| 197 |
+
|
| 198 |
+
def readinto1(self, b):
|
| 199 |
+
"""Read bytes into b, while trying to avoid making multiple reads
|
| 200 |
+
from the underlying stream.
|
| 201 |
+
|
| 202 |
+
Returns the number of bytes read (0 for EOF).
|
| 203 |
+
"""
|
| 204 |
+
self._check_can_read()
|
| 205 |
+
return self._buffer.readinto1(b)
|
| 206 |
+
|
| 207 |
+
def readline(self, size=-1):
|
| 208 |
+
"""Read a line of uncompressed bytes from the file.
|
| 209 |
+
|
| 210 |
+
The terminating newline (if present) is retained. If size is
|
| 211 |
+
non-negative, no more than size bytes will be read (in which
|
| 212 |
+
case the line may be incomplete). Returns b'' if already at EOF.
|
| 213 |
+
"""
|
| 214 |
+
self._check_can_read()
|
| 215 |
+
return self._buffer.readline(size)
|
| 216 |
+
|
| 217 |
+
def seek(self, offset, whence=io.SEEK_SET):
|
| 218 |
+
"""Change the file position.
|
| 219 |
+
|
| 220 |
+
The new position is specified by offset, relative to the
|
| 221 |
+
position indicated by whence. Possible values for whence are:
|
| 222 |
+
|
| 223 |
+
0: start of stream (default): offset must not be negative
|
| 224 |
+
1: current stream position
|
| 225 |
+
2: end of stream; offset must not be positive
|
| 226 |
+
|
| 227 |
+
Returns the new file position.
|
| 228 |
+
|
| 229 |
+
Note that seeking is emulated, so depending on the arguments,
|
| 230 |
+
this operation may be extremely slow.
|
| 231 |
+
"""
|
| 232 |
+
self._check_can_read()
|
| 233 |
+
|
| 234 |
+
# BufferedReader.seek() checks seekable
|
| 235 |
+
return self._buffer.seek(offset, whence)
|
| 236 |
+
|
| 237 |
+
def peek(self, size=-1):
|
| 238 |
+
"""Return buffered data without advancing the file position.
|
| 239 |
+
|
| 240 |
+
Always returns at least one byte of data, unless at EOF.
|
| 241 |
+
The exact number of bytes returned is unspecified.
|
| 242 |
+
"""
|
| 243 |
+
# Relies on the undocumented fact that BufferedReader.peek() always
|
| 244 |
+
# returns at least one byte (except at EOF)
|
| 245 |
+
self._check_can_read()
|
| 246 |
+
return self._buffer.peek(size)
|
| 247 |
+
|
| 248 |
+
def __next__(self):
|
| 249 |
+
if ret := self._buffer.readline():
|
| 250 |
+
return ret
|
| 251 |
+
raise StopIteration
|
| 252 |
+
|
| 253 |
+
def tell(self):
|
| 254 |
+
"""Return the current file position."""
|
| 255 |
+
self._check_not_closed()
|
| 256 |
+
if self._mode == _MODE_READ:
|
| 257 |
+
return self._buffer.tell()
|
| 258 |
+
elif self._mode == _MODE_WRITE:
|
| 259 |
+
return self._pos
|
| 260 |
+
|
| 261 |
+
def fileno(self):
|
| 262 |
+
"""Return the file descriptor for the underlying file."""
|
| 263 |
+
self._check_not_closed()
|
| 264 |
+
return self._fp.fileno()
|
| 265 |
+
|
| 266 |
+
@property
|
| 267 |
+
def name(self):
|
| 268 |
+
self._check_not_closed()
|
| 269 |
+
return self._fp.name
|
| 270 |
+
|
| 271 |
+
@property
|
| 272 |
+
def mode(self):
|
| 273 |
+
return 'wb' if self._mode == _MODE_WRITE else 'rb'
|
| 274 |
+
|
| 275 |
+
@property
|
| 276 |
+
def closed(self):
|
| 277 |
+
"""True if this file is closed."""
|
| 278 |
+
return self._mode == _MODE_CLOSED
|
| 279 |
+
|
| 280 |
+
def seekable(self):
|
| 281 |
+
"""Return whether the file supports seeking."""
|
| 282 |
+
return self.readable() and self._buffer.seekable()
|
| 283 |
+
|
| 284 |
+
def readable(self):
|
| 285 |
+
"""Return whether the file was opened for reading."""
|
| 286 |
+
self._check_not_closed()
|
| 287 |
+
return self._mode == _MODE_READ
|
| 288 |
+
|
| 289 |
+
def writable(self):
|
| 290 |
+
"""Return whether the file was opened for writing."""
|
| 291 |
+
self._check_not_closed()
|
| 292 |
+
return self._mode == _MODE_WRITE
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def open(file, /, mode='rb', *, level=None, options=None, zstd_dict=None,
|
| 296 |
+
encoding=None, errors=None, newline=None):
|
| 297 |
+
"""Open a Zstandard compressed file in binary or text mode.
|
| 298 |
+
|
| 299 |
+
file can be either a file name (given as a str, bytes, or PathLike object),
|
| 300 |
+
in which case the named file is opened, or it can be an existing file object
|
| 301 |
+
to read from or write to.
|
| 302 |
+
|
| 303 |
+
The mode parameter can be 'r', 'rb' (default), 'w', 'wb', 'x', 'xb', 'a',
|
| 304 |
+
'ab' for binary mode, or 'rt', 'wt', 'xt', 'at' for text mode.
|
| 305 |
+
|
| 306 |
+
The level, options, and zstd_dict parameters specify the settings the same
|
| 307 |
+
as ZstdFile.
|
| 308 |
+
|
| 309 |
+
When using read mode (decompression), the options parameter is a dict
|
| 310 |
+
representing advanced decompression options. The level parameter is not
|
| 311 |
+
supported in this case. When using write mode (compression), only one of
|
| 312 |
+
level, an int representing the compression level, or options, a dict
|
| 313 |
+
representing advanced compression options, may be passed. In both modes,
|
| 314 |
+
zstd_dict is a ZstdDict instance containing a trained Zstandard dictionary.
|
| 315 |
+
|
| 316 |
+
For binary mode, this function is equivalent to the ZstdFile constructor:
|
| 317 |
+
ZstdFile(filename, mode, ...). In this case, the encoding, errors and
|
| 318 |
+
newline parameters must not be provided.
|
| 319 |
+
|
| 320 |
+
For text mode, an ZstdFile object is created, and wrapped in an
|
| 321 |
+
io.TextIOWrapper instance with the specified encoding, error handling
|
| 322 |
+
behavior, and line ending(s).
|
| 323 |
+
"""
|
| 324 |
+
|
| 325 |
+
text_mode = 't' in mode
|
| 326 |
+
mode = mode.replace('t', '')
|
| 327 |
+
|
| 328 |
+
if text_mode:
|
| 329 |
+
if 'b' in mode:
|
| 330 |
+
raise ValueError(f'Invalid mode: {mode!r}')
|
| 331 |
+
else:
|
| 332 |
+
if encoding is not None:
|
| 333 |
+
raise ValueError('Argument "encoding" not supported in binary mode')
|
| 334 |
+
if errors is not None:
|
| 335 |
+
raise ValueError('Argument "errors" not supported in binary mode')
|
| 336 |
+
if newline is not None:
|
| 337 |
+
raise ValueError('Argument "newline" not supported in binary mode')
|
| 338 |
+
|
| 339 |
+
binary_file = ZstdFile(file, mode, level=level, options=options,
|
| 340 |
+
zstd_dict=zstd_dict)
|
| 341 |
+
|
| 342 |
+
if text_mode:
|
| 343 |
+
return io.TextIOWrapper(binary_file, encoding, errors, newline)
|
| 344 |
+
else:
|
| 345 |
+
return binary_file
|
micromamba_root/envs/hf_sync/Lib/concurrent/__pycache__/__init__.cpython-314.pyc
ADDED
|
Binary file (125 Bytes). View file
|
|
|