Bug 1240134 - Allow JARReader to read data already in memory; r?glandium
This will be needed to teach artifact builds to extract files from
omni.ja files whose content is loaded into memory (from a tar
archive).
MozReview-Commit-ID: LH2HkKx5Zj3
--- a/python/mozbuild/mozpack/mozjar.py
+++ b/python/mozbuild/mozpack/mozjar.py
@@ -327,24 +327,24 @@ class JarFileReader(object):
return self._uncompressed_data
class JarReader(object):
'''
Class with methods to read Jar files. Can open standard jar files as well
as Mozilla jar files (see further details in the JarWriter documentation).
'''
- def __init__(self, file=None, fileobj=None):
+ def __init__(self, file=None, fileobj=None, data=None):
'''
Opens the given file as a Jar archive. Use the given file-like object
if one is given instead of opening the given file name.
'''
if fileobj:
data = fileobj.read()
- else:
+ elif file:
data = open(file, 'rb').read()
self._data = memoryview(data)
# The End of Central Directory Record has a variable size because of
# comments it may contain, so scan for it from the end of the file.
offset = -CDIR_END_SIZE
while True:
signature = JarStruct.get_data('uint32', self._data[offset:])[0]
if signature == JarCdirEnd.MAGIC: