You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

683 lines
24 KiB

  1. # Copyright (c) 2011, SmartFile <btimby@smartfile.com>
  2. # All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are met:
  6. # * Redistributions of source code must retain the above copyright
  7. # notice, this list of conditions and the following disclaimer.
  8. # * Redistributions in binary form must reproduce the above copyright
  9. # notice, this list of conditions and the following disclaimer in the
  10. # documentation and/or other materials provided with the distribution.
  11. # * Neither the name of the organization nor the
  12. # names of its contributors may be used to endorse or promote products
  13. # derived from this software without specific prior written permission.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
  19. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. import os
  26. import stat
  27. import sys
  28. import time
  29. import warnings
  30. from ctypes import cdll, c_char_p
  31. from libarchive import _libarchive
  32. from io import StringIO
  33. PY3 = sys.version_info[0] == 3
  34. # Suggested block size for libarchive. Libarchive may adjust it.
  35. BLOCK_SIZE = 10240
  36. MTIME_FORMAT = ''
  37. # Default encoding scheme.
  38. ENCODING = 'utf-8'
  39. # Functions to initialize read/write for various libarchive supported formats and filters.
  40. FORMATS = {
  41. None: (_libarchive.archive_read_support_format_all, None),
  42. 'tar': (_libarchive.archive_read_support_format_tar, _libarchive.archive_write_set_format_ustar),
  43. 'pax': (_libarchive.archive_read_support_format_tar, _libarchive.archive_write_set_format_pax),
  44. 'gnu': (_libarchive.archive_read_support_format_gnutar, _libarchive.archive_write_set_format_gnutar),
  45. 'zip': (_libarchive.archive_read_support_format_zip, _libarchive.archive_write_set_format_zip),
  46. 'rar': (_libarchive.archive_read_support_format_rar, None),
  47. '7zip': (_libarchive.archive_read_support_format_7zip, None),
  48. 'ar': (_libarchive.archive_read_support_format_ar, None),
  49. 'cab': (_libarchive.archive_read_support_format_cab, None),
  50. 'cpio': (_libarchive.archive_read_support_format_cpio, _libarchive.archive_write_set_format_cpio_newc),
  51. 'iso': (_libarchive.archive_read_support_format_iso9660, _libarchive.archive_write_set_format_iso9660),
  52. 'lha': (_libarchive.archive_read_support_format_lha, None),
  53. 'xar': (_libarchive.archive_read_support_format_xar, _libarchive.archive_write_set_format_xar),
  54. }
  55. FILTERS = {
  56. None: (_libarchive.archive_read_support_filter_all, _libarchive.archive_write_add_filter_none),
  57. 'gz': (_libarchive.archive_read_support_filter_gzip, _libarchive.archive_write_add_filter_gzip),
  58. 'bz2': (_libarchive.archive_read_support_filter_bzip2, _libarchive.archive_write_add_filter_bzip2),
  59. }
  60. # Map file extensions to formats and filters. To support quick detection.
  61. FORMAT_EXTENSIONS = {
  62. '.tar': 'tar',
  63. '.zip': 'zip',
  64. '.rar': 'rar',
  65. '.7z': '7zip',
  66. '.ar': 'ar',
  67. '.cab': 'cab',
  68. '.rpm': 'cpio',
  69. '.cpio': 'cpio',
  70. '.iso': 'iso',
  71. '.lha': 'lha',
  72. '.xar': 'xar',
  73. }
  74. FILTER_EXTENSIONS = {
  75. '.gz': 'gz',
  76. '.bz2': 'bz2',
  77. }
  78. class EOF(Exception):
  79. '''Raised by ArchiveInfo.from_archive() when unable to read the next
  80. archive header.'''
  81. pass
  82. def get_error(archive):
  83. '''Retrieves the last error description for the given archive instance.'''
  84. return _libarchive.archive_error_string(archive)
  85. def call_and_check(func, archive, *args):
  86. '''Executes a libarchive function and raises an exception when appropriate.'''
  87. ret = func(*args)
  88. if ret == _libarchive.ARCHIVE_OK:
  89. return
  90. elif ret == _libarchive.ARCHIVE_WARN:
  91. warnings.warn('Warning executing function: %s.' % get_error(archive), RuntimeWarning)
  92. elif ret == _libarchive.ARCHIVE_EOF:
  93. raise EOF()
  94. else:
  95. raise Exception('Fatal error executing function, message is: %s.' % get_error(archive))
  96. def get_func(name, items, index):
  97. item = items.get(name, None)
  98. if item is None:
  99. return None
  100. return item[index]
  101. def guess_format(filename):
  102. if isinstance(filename, int):
  103. filename = ext = ''
  104. else:
  105. filename, ext = os.path.splitext(filename)
  106. filter = FILTER_EXTENSIONS.get(ext)
  107. if filter:
  108. filename, ext = os.path.splitext(filename)
  109. format = FORMAT_EXTENSIONS.get(ext)
  110. return format, filter
  111. def is_archive_name(filename, formats=None):
  112. '''Quick check to see if the given file has an extension indiciating that it is
  113. an archive. The format parameter can be used to limit what archive format is acceptable.
  114. If omitted, all supported archive formats will be checked.
  115. This function will return the name of the most likely archive format, None if the file is
  116. unlikely to be an archive.'''
  117. if formats is None:
  118. formats = list(FORMAT_EXTENSIONS.values())
  119. format, filter = guess_format(filename)
  120. if format in formats:
  121. return format
  122. def is_archive(f, formats=(None, ), filters=(None, )):
  123. '''Check to see if the given file is actually an archive. The format parameter
  124. can be used to specify which archive format is acceptable. If ommitted, all supported
  125. archive formats will be checked. It opens the file using libarchive. If no error is
  126. received, the file was successfully detected by the libarchive bidding process.
  127. This procedure is quite costly, so you should avoid calling it unless you are reasonably
  128. sure that the given file is an archive. In other words, you may wish to filter large
  129. numbers of file names using is_archive_name() before double-checking the positives with
  130. this function.
  131. This function will return True if the file can be opened as an archive using the given
  132. format(s)/filter(s).'''
  133. if isinstance(f, str):
  134. f = open(f, 'r')
  135. a = _libarchive.archive_read_new()
  136. for format in formats:
  137. format = get_func(format, FORMATS, 0)
  138. if format is None:
  139. return False
  140. format(a)
  141. for filter in filters:
  142. filter = get_func(filter, FILTERS, 0)
  143. if filter is None:
  144. return False
  145. filter(a)
  146. try:
  147. try:
  148. call_and_check(_libarchive.archive_read_open_fd, a, a, f.fileno(), BLOCK_SIZE)
  149. return True
  150. except:
  151. return False
  152. finally:
  153. _libarchive.archive_read_close(a)
  154. _libarchive.archive_read_free(a)
  155. f.close()
  156. class EntryReadStream(object):
  157. '''A file-like object for reading an entry from the archive.'''
  158. def __init__(self, archive, size):
  159. self.archive = archive
  160. self.closed = False
  161. self.size = size
  162. self.bytes = 0
  163. def __enter__(self):
  164. return self
  165. def __exit__(self, *args):
  166. return
  167. def __iter__(self):
  168. if self.closed:
  169. return
  170. while True:
  171. data = self.read(BLOCK_SIZE)
  172. if not data:
  173. break
  174. yield data
  175. def __len__(self):
  176. return self.size
  177. def tell(self):
  178. return self.bytes
  179. def read(self, bytes=-1):
  180. if self.closed:
  181. return
  182. if self.bytes == self.size:
  183. # EOF already reached.
  184. return
  185. if bytes < 0:
  186. bytes = self.size - self.bytes
  187. elif self.bytes + bytes > self.size:
  188. # Limit read to remaining bytes
  189. bytes = self.size - self.bytes
  190. # Read requested bytes
  191. data = _libarchive.archive_read_data_into_str(self.archive._a, bytes)
  192. self.bytes += len(data)
  193. return data
  194. def close(self):
  195. if self.closed:
  196. return
  197. # Call archive.close() with _defer True to let it know we have been
  198. # closed and it is now safe to actually close.
  199. self.archive.close(_defer=True)
  200. self.archive = None
  201. self.closed = True
  202. class EntryWriteStream(object):
  203. '''A file-like object for writing an entry to an archive.
  204. If the size is known ahead of time and provided, then the file contents
  205. are not buffered but flushed directly to the archive. If size is omitted,
  206. then the file contents are buffered and flushed in the close() method.'''
  207. def __init__(self, archive, pathname, size=None):
  208. self.archive = archive
  209. self.entry = Entry(pathname=pathname, mtime=time.time(), mode=stat.S_IFREG)
  210. if size is None:
  211. self.buffer = StringIO()
  212. else:
  213. self.buffer = None
  214. self.entry.size = size
  215. self.entry.to_archive(self.archive)
  216. self.bytes = 0
  217. self.closed = False
  218. def __enter__(self):
  219. return self
  220. def __exit__(self, *args):
  221. self.close()
  222. def __del__(self):
  223. self.close()
  224. def __len__(self):
  225. return self.bytes
  226. def tell(self):
  227. return self.bytes
  228. def write(self, data):
  229. if self.closed:
  230. raise Exception('Cannot write to closed stream.')
  231. if self.buffer:
  232. self.buffer.write(data)
  233. else:
  234. _libarchive.archive_write_data_from_str(self.archive._a, data.encode('utf-8'))
  235. self.bytes += len(data)
  236. def close(self):
  237. if self.closed:
  238. return
  239. if self.buffer:
  240. self.entry.size = self.buffer.tell()
  241. self.entry.to_archive(self.archive)
  242. _libarchive.archive_write_data_from_str(self.archive._a, self.buffer.getvalue().encode('utf-8'))
  243. _libarchive.archive_write_finish_entry(self.archive._a)
  244. # Call archive.close() with _defer True to let it know we have been
  245. # closed and it is now safe to actually close.
  246. self.archive.close(_defer=True)
  247. self.archive = None
  248. self.closed = True
  249. class Entry(object):
  250. '''An entry within an archive. Represents the header data and it's location within the archive.'''
  251. def __init__(self, pathname=None, size=None, mtime=None, mode=None, hpos=None, encoding=ENCODING, symlink=None):
  252. self.pathname = pathname
  253. self.size = size
  254. self.mtime = mtime
  255. self.mode = mode
  256. self.hpos = hpos
  257. self.encoding = encoding
  258. if self.issym():
  259. self.symlink = symlink
  260. else:
  261. self.symlink = None
  262. @property
  263. def header_position(self):
  264. return self.hpos
  265. @classmethod
  266. def from_archive(cls, archive, encoding=ENCODING):
  267. '''Instantiates an Entry class and sets all the properties from an archive header.'''
  268. e = _libarchive.archive_entry_new()
  269. try:
  270. call_and_check(_libarchive.archive_read_next_header2, archive._a, archive._a, e)
  271. mode = _libarchive.archive_entry_filetype(e)
  272. mode |= _libarchive.archive_entry_perm(e)
  273. if PY3:
  274. pathname = _libarchive.archive_entry_pathname(e)
  275. else:
  276. pathname = _libarchive.archive_entry_pathname(e).decode(encoding)
  277. entry = cls(
  278. pathname=pathname,
  279. size=_libarchive.archive_entry_size(e),
  280. mtime=_libarchive.archive_entry_mtime(e),
  281. mode=mode,
  282. hpos=archive.header_position,
  283. )
  284. symLinkPath = ""
  285. if entry.issym():
  286. libarchive.archive_entry_copy_symlink(e, symLinkPath)
  287. print(symLinkPath)
  288. finally:
  289. _libarchive.archive_entry_free(e)
  290. return entry
  291. @classmethod
  292. def from_file(cls, f, entry=None, encoding=ENCODING):
  293. '''Instantiates an Entry class and sets all the properties from a file on the file system.
  294. f can be a file-like object or a path.'''
  295. if entry is None:
  296. entry = cls(encoding=encoding)
  297. if entry.pathname is None:
  298. if isinstance(f, str):
  299. st = os.stat(f)
  300. entry.pathname = f
  301. entry.size = st.st_size
  302. entry.mtime = st.st_mtime
  303. entry.mode = st.st_mode
  304. elif hasattr(f, 'fileno'):
  305. st = os.fstat(f.fileno())
  306. entry.pathname = getattr(f, 'name', None)
  307. entry.size = st.st_size
  308. entry.mtime = st.st_mtime
  309. entry.mode = st.st_mode
  310. else:
  311. entry.pathname = getattr(f, 'pathname', None)
  312. entry.size = getattr(f, 'size', 0)
  313. entry.mtime = getattr(f, 'mtime', time.time())
  314. entry.mode = stat.S_IFREG
  315. return entry
  316. def to_archive(self, archive):
  317. '''Creates an archive header and writes it to the given archive.'''
  318. e = _libarchive.archive_entry_new()
  319. try:
  320. if PY3:
  321. _libarchive.archive_entry_set_pathname(e, self.pathname)
  322. else:
  323. _libarchive.archive_entry_set_pathname(e, self.pathname.encode(self.encoding))
  324. _libarchive.archive_entry_set_filetype(e, stat.S_IFMT(self.mode))
  325. _libarchive.archive_entry_set_perm(e, stat.S_IMODE(self.mode))
  326. _libarchive.archive_entry_set_size(e, self.size)
  327. _libarchive.archive_entry_set_mtime(e, self.mtime, 0)
  328. call_and_check(_libarchive.archive_write_header, archive._a, archive._a, e)
  329. #self.hpos = archive.header_position
  330. finally:
  331. _libarchive.archive_entry_free(e)
  332. def isdir(self):
  333. return stat.S_ISDIR(self.mode)
  334. def isfile(self):
  335. return stat.S_ISREG(self.mode)
  336. def issym(self):
  337. return stat.S_ISLNK(self.mode)
  338. def isfifo(self):
  339. return stat.S_ISFIFO(self.mode)
  340. def ischr(self):
  341. return stat.S_ISCHR(self.mode)
  342. def isblk(self):
  343. return stat.S_ISBLK(self.mode)
  344. class Archive(object):
  345. '''A low-level archive reader which provides forward-only iteration. Consider
  346. this a light-weight pythonic libarchive wrapper.'''
  347. def __init__(self, f, mode='r', format=None, filter=None, entry_class=Entry, encoding=ENCODING, blocksize=BLOCK_SIZE):
  348. assert mode in ('r', 'w', 'wb', 'a'), 'Mode should be "r", "w", "wb", or "a".'
  349. self._stream = None
  350. self.encoding = encoding
  351. self.blocksize = blocksize
  352. if isinstance(f, str):
  353. self.filename = f
  354. f = open(f, mode)
  355. # Only close it if we opened it...
  356. self._defer_close = True
  357. elif hasattr(f, 'fileno'):
  358. self.filename = getattr(f, 'name', None)
  359. # Leave the fd alone, caller should manage it...
  360. self._defer_close = False
  361. else:
  362. raise Exception('Provided file is not path or open file.')
  363. self.f = f
  364. self.mode = mode
  365. # Guess the format/filter from file name (if not provided)
  366. if self.filename:
  367. if format is None:
  368. format = guess_format(self.filename)[0]
  369. if filter is None:
  370. filter = guess_format(self.filename)[1]
  371. self.format = format
  372. self.filter = filter
  373. # The class to use for entries.
  374. self.entry_class = entry_class
  375. # Select filter/format functions.
  376. if self.mode == 'r':
  377. self.format_func = get_func(self.format, FORMATS, 0)
  378. if self.format_func is None:
  379. raise Exception('Unsupported format %s' % format)
  380. self.filter_func = get_func(self.filter, FILTERS, 0)
  381. if self.filter_func is None:
  382. raise Exception('Unsupported filter %s' % filter)
  383. else:
  384. # TODO: how to support appending?
  385. if self.format is None:
  386. raise Exception('You must specify a format for writing.')
  387. self.format_func = get_func(self.format, FORMATS, 1)
  388. if self.format_func is None:
  389. raise Exception('Unsupported format %s' % format)
  390. self.filter_func = get_func(self.filter, FILTERS, 1)
  391. if self.filter_func is None:
  392. raise Exception('Unsupported filter %s' % filter)
  393. # Open the archive, apply filter/format functions.
  394. self.init()
  395. def __iter__(self):
  396. while True:
  397. try:
  398. yield self.entry_class.from_archive(self, encoding=self.encoding)
  399. except EOF:
  400. break
  401. def __enter__(self):
  402. return self
  403. def __exit__(self, type, value, traceback):
  404. self.denit()
  405. def __del__(self):
  406. self.close()
  407. def init(self):
  408. if self.mode == 'r':
  409. self._a = _libarchive.archive_read_new()
  410. else:
  411. self._a = _libarchive.archive_write_new()
  412. self.format_func(self._a)
  413. self.filter_func(self._a)
  414. if self.mode == 'r':
  415. call_and_check(_libarchive.archive_read_open_fd, self._a, self._a, self.f.fileno(), self.blocksize)
  416. else:
  417. call_and_check(_libarchive.archive_write_open_fd, self._a, self._a, self.f.fileno())
  418. def denit(self):
  419. '''Closes and deallocates the archive reader/writer.'''
  420. if getattr(self, '_a', None) is None:
  421. return
  422. try:
  423. if self.mode == 'r':
  424. _libarchive.archive_read_close(self._a)
  425. _libarchive.archive_read_free(self._a)
  426. elif self.mode == 'w':
  427. _libarchive.archive_write_close(self._a)
  428. _libarchive.archive_write_free(self._a)
  429. finally:
  430. # We only want one try at this...
  431. self._a = None
  432. def close(self, _defer=False):
  433. # _defer == True is how a stream can notify Archive that the stream is
  434. # now closed. Calling it directly in not recommended.
  435. if _defer:
  436. # This call came from our open stream.
  437. self._stream = None
  438. if not self._defer_close:
  439. # We are not yet ready to close.
  440. return
  441. if self._stream is not None:
  442. # We have a stream open! don't close, but remember we were asked to.
  443. self._defer_close = True
  444. return
  445. self.denit()
  446. # If there is a file attached...
  447. if hasattr(self, 'f'):
  448. # Make sure it is not already closed...
  449. if getattr(self.f, 'closed', False):
  450. return
  451. # Flush it if not read-only...
  452. if self.f.mode != 'r' and self.f.mode != 'rb':
  453. self.f.flush()
  454. os.fsync(self.f.fileno())
  455. # and then close it, if we opened it...
  456. if getattr(self, '_close', None):
  457. self.f.close()
  458. @property
  459. def header_position(self):
  460. '''The position within the file.'''
  461. return _libarchive.archive_read_header_position(self._a)
  462. def iterpaths(self):
  463. for entry in self:
  464. yield entry.pathname
  465. def read(self, size):
  466. '''Read current archive entry contents into string.'''
  467. return _libarchive.archive_read_data_into_str(self._a, size)
  468. def readpath(self, f):
  469. '''Write current archive entry contents to file. f can be a file-like object or
  470. a path.'''
  471. if isinstance(f, str):
  472. basedir = os.path.basename(f)
  473. if not os.path.exists(basedir):
  474. os.makedirs(basedir)
  475. f = open(f, 'w')
  476. return _libarchive.archive_read_data_into_fd(self._a, f.fileno())
  477. def readstream(self, size):
  478. '''Returns a file-like object for reading current archive entry contents.'''
  479. self._stream = EntryReadStream(self, size)
  480. return self._stream
  481. def write(self, member, data=None):
  482. '''Writes a string buffer to the archive as the given entry.'''
  483. if isinstance(member, str):
  484. member = self.entry_class(pathname=member, encoding=self.encoding)
  485. if data:
  486. member.size = len(data)
  487. member.to_archive(self)
  488. if data:
  489. if PY3:
  490. if isinstance(data, bytes):
  491. result = _libarchive.archive_write_data_from_str(self._a, data)
  492. else:
  493. result = _libarchive.archive_write_data_from_str(self._a, data.encode('utf8'))
  494. else:
  495. result = _libarchive.archive_write_data_from_str(self._a, data)
  496. _libarchive.archive_write_finish_entry(self._a)
  497. def writepath(self, f, pathname=None, folder=False):
  498. '''Writes a file to the archive. f can be a file-like object or a path. Uses
  499. write() to do the actual writing.'''
  500. member = self.entry_class.from_file(f, encoding=self.encoding)
  501. if isinstance(f, str):
  502. if os.path.isfile(f):
  503. f = open(f, 'r')
  504. if pathname:
  505. member.pathname = pathname
  506. if folder and not member.isdir():
  507. member.mode = stat.S_IFDIR
  508. if hasattr(f, 'read'):
  509. # TODO: optimize this to write directly from f to archive.
  510. self.write(member, data=f.read())
  511. else:
  512. self.write(member)
  513. def writestream(self, pathname, size=None):
  514. '''Returns a file-like object for writing a new entry.'''
  515. self._stream = EntryWriteStream(self, pathname, size)
  516. return self._stream
  517. def printlist(self, s=sys.stdout):
  518. for entry in self:
  519. s.write(entry.size)
  520. s.write('\t')
  521. s.write(entry.mtime.strftime(MTIME_FORMAT))
  522. s.write('\t')
  523. s.write(entry.pathname)
  524. s.flush()
  525. class SeekableArchive(Archive):
  526. '''A class that provides random-access to archive entries. It does this by using one
  527. or many Archive instances to seek to the correct location. The best performance will
  528. occur when reading archive entries in the order in which they appear in the archive.
  529. Reading out of order will cause the archive to be closed and opened each time a
  530. reverse seek is needed.'''
  531. def __init__(self, f, **kwargs):
  532. self._stream = None
  533. # Convert file to open file. We need this to reopen the archive.
  534. mode = kwargs.setdefault('mode', 'r')
  535. if isinstance(f, str):
  536. f = open(f, mode)
  537. super(SeekableArchive, self).__init__(f, **kwargs)
  538. self.entries = []
  539. self.eof = False
  540. def __iter__(self):
  541. for entry in self.entries:
  542. yield entry
  543. if not self.eof:
  544. try:
  545. for entry in super(SeekableArchive, self).__iter__():
  546. self.entries.append(entry)
  547. yield entry
  548. except StopIteration:
  549. self.eof = True
  550. def reopen(self):
  551. '''Seeks the underlying fd to 0 position, then opens the archive. If the archive
  552. is already open, this will effectively re-open it (rewind to the beginning).'''
  553. self.denit()
  554. self.f.seek(0)
  555. self.init()
  556. def getentry(self, pathname):
  557. '''Take a name or entry object and returns an entry object.'''
  558. for entry in self:
  559. if entry.pathname == pathname:
  560. return entry
  561. raise KeyError(pathname)
  562. def seek(self, entry):
  563. '''Seeks the archive to the requested entry. Will reopen if necessary.'''
  564. move = entry.header_position - self.header_position
  565. if move != 0:
  566. if move < 0:
  567. # can't move back, re-open archive:
  568. self.reopen()
  569. # move to proper position in stream
  570. for curr in super(SeekableArchive, self).__iter__():
  571. if curr.header_position == entry.header_position:
  572. break
  573. def read(self, member):
  574. '''Return the requested archive entry contents as a string.'''
  575. entry = self.getentry(member)
  576. self.seek(entry)
  577. return super(SeekableArchive, self).read(entry.size)
  578. def readpath(self, member, f):
  579. entry = self.getentry(member)
  580. self.seek(entry)
  581. return super(SeekableArchive, self).readpath(f)
  582. def readstream(self, member):
  583. '''Returns a file-like object for reading requested archive entry contents.'''
  584. entry = self.getentry(member)
  585. self.seek(entry)
  586. self._stream = EntryReadStream(self, entry.size)
  587. return self._stream