Bug 1240134 - Allow JARReader to read data already in memory; r?glandium draft
authorGregory Szorc <gps@mozilla.com>
Fri, 19 Feb 2016 22:35:49 -0800
changeset 333936 266928b5a7615fa054c70adf0f649cbb3f085e8d
parent 333935 9004d5a02a3a3f75bcf4009c875f183f73d866cd
child 333937 d988bd2c434df66c299b6878d57b07a723b00a71
push id11397
push usergszorc@mozilla.com
push dateTue, 23 Feb 2016 22:51:52 +0000
reviewersglandium
bugs1240134
milestone47.0a1
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
python/mozbuild/mozpack/mozjar.py
--- 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: