mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-08 13:43:39 +02:00
Rename lzma module to calibre_lzma
This commit is contained in:
parent
4a45f32357
commit
b62a5af46c
5 changed files with 13 additions and 8 deletions
|
|
@ -37,7 +37,7 @@
|
|||
from calibre.utils.img import image_from_data, Canvas, optimize_png, optimize_jpeg
|
||||
from calibre.utils.zipfile import ZipFile, ZIP_STORED
|
||||
from calibre.utils.filenames import atomic_rename
|
||||
from lzma.xz import compress, decompress
|
||||
from calibre_lzma.xz import compress, decompress
|
||||
from polyglot.builtins import iteritems, map, range, reraise, filter, as_bytes, unicode_type
|
||||
from polyglot import http_client
|
||||
from polyglot.queue import Queue, Empty
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ def test_chardet(self):
|
|||
self.assertEqual(detector.result['encoding'], 'utf-8')
|
||||
|
||||
def test_lzma(self):
|
||||
from lzma.xz import test_lzma2
|
||||
from calibre_lzma.xz import test_lzma2
|
||||
test_lzma2()
|
||||
|
||||
def test_html5lib(self):
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ def abspath(x):
|
|||
|
||||
|
||||
def update_rapydscript():
|
||||
from lzma.xz import compress
|
||||
from calibre_lzma.xz import compress
|
||||
d = os.path.dirname
|
||||
base = d(d(d(d(d(abspath(__file__))))))
|
||||
base = os.path.join(base, 'rapydscript')
|
||||
|
|
@ -51,7 +51,7 @@ def to_dict(obj):
|
|||
|
||||
|
||||
def compiler():
|
||||
from lzma.xz import decompress
|
||||
from calibre_lzma.xz import decompress
|
||||
ans = getattr(compiler, 'ans', None)
|
||||
if ans is not None:
|
||||
return ans
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@
|
|||
from struct import unpack
|
||||
|
||||
from calibre.ptempfile import SpooledTemporaryFile
|
||||
from lzma.errors import NotLzma, lzma
|
||||
from .errors import NotLzma, lzma
|
||||
|
||||
|
||||
def read_header(f):
|
||||
raw = f.read(13)
|
||||
|
|
@ -21,17 +22,21 @@ def read_header(f):
|
|||
raise NotLzma('Not a LZMA file')
|
||||
return uncompressed_size, raw
|
||||
|
||||
def decompress(raw, outfile=None, bufsize=10*1024*1024):
|
||||
|
||||
def decompress(raw, outfile=None, bufsize=10 * 1024 * 1024):
|
||||
if isinstance(raw, bytes):
|
||||
raw = BytesIO(raw)
|
||||
uncompressed_size, header = read_header(raw)
|
||||
outfile = outfile or SpooledTemporaryFile(50 * 1024 * 1024, '_lzma_decompress')
|
||||
lzma.decompress(raw.read, raw.seek, outfile.write, uncompressed_size, header, bufsize)
|
||||
lzma.decompress(
|
||||
raw.read, raw.seek, outfile.write, uncompressed_size, header, bufsize
|
||||
)
|
||||
if uncompressed_size < outfile.tell():
|
||||
outfile.seek(uncompressed_size)
|
||||
outfile.truncate()
|
||||
return outfile
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
decompress(open(sys.argv[-1], 'rb'))
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
from binascii import crc32 as _crc32
|
||||
|
||||
from calibre.ptempfile import SpooledTemporaryFile
|
||||
from lzma.errors import NotXZ, InvalidXZ, lzma
|
||||
from .errors import NotXZ, InvalidXZ, lzma
|
||||
from polyglot.builtins import error_message
|
||||
|
||||
HEADER_MAGIC = b'\xfd7zXZ\0'
|
||||
|
|
|
|||
Loading…
Reference in a new issue