def createFields(self):
        yield String(self, "id", 3, "Identifier (BZh)", charset="ASCII")
        yield Character(self, "blocksize",
                        "Block size (KB of memory needed to uncompress)")

        if self._size is None:  # TODO: is it possible to handle piped input?
            raise NotImplementedError

        size = (self._size - self.current_size) / 8
        if size:
            for tag, filename in self.stream.tags:
                if tag == "filename" and filename.endswith(".bz2"):
                    filename = filename[:-4]
                    break
            else:
                filename = None
            data = Bzip2Stream(self, "file", size=size * 8)
            if has_deflate:
                CompressedField(self, Bunzip2)

                def createInputStream(**args):
                    if filename:
                        args.setdefault("tags", []).append(
                            ("filename", filename))
                    return self._createInputStream(**args)

                data._createInputStream = createInputStream
            yield data
Esempio n. 2
0
 def __init__(self, parent, name="compressed_data"):
     Fragment.__init__(self, parent, name, None, 8*parent["size"].value)
     data = parent.name.split('[')
     data, next = "../%s[%%u]" % data[0], int(data[1][:-1]) + 1
     first = parent.getField(data % 0)
     if first is parent:
         first = None
         if has_deflate:
             CompressedField(self, Gunzip)
     else:
         first = first[name]
     try:
         _next = parent[data % next]
         next = lambda: _next[name]
     except MissingField:
         next = None
     self.setLinks(first, next)
    def createFields(self):
        yield String(self, "id", 3, "Identifier (BZh)", charset="ASCII")
        yield Character(self, "blocksize",
                        "Block size (KB of memory needed to uncompress)")

        yield UInt8(self, "blockheader", "Block header")
        if self["blockheader"].value == 0x17:
            yield String(self, "id2", 4, "Identifier2 (re8P)", charset="ASCII")
            yield UInt8(self, "id3", "Identifier3 (0x90)")
        elif self["blockheader"].value == 0x31:
            yield String(self,
                         "id2",
                         5,
                         "Identifier 2 (AY&SY)",
                         charset="ASCII")
            if self["id2"].value != "AY&SY":
                raise ParserError("Invalid identifier 2 (AY&SY)!")
        else:
            raise ParserError("Invalid block header!")
        yield textHandler(UInt32(self, "crc32", "CRC32"), hexadecimal)

        if self._size is None:  # TODO: is it possible to handle piped input?
            raise NotImplementedError

        size = (self._size - self.current_size) / 8
        if size:
            for tag, filename in self.stream.tags:
                if tag == "filename" and filename.endswith(".bz2"):
                    filename = filename[:-4]
                    break
            else:
                filename = None
            data = Bytes(self, "file", size)
            if has_deflate:
                CompressedField(self, Bunzip2)

                def createInputStream(**args):
                    if filename:
                        args.setdefault("tags", []).append(
                            ("filename", filename))
                    return self._createInputStream(**args)

                data._createInputStream = createInputStream
            yield data
Esempio n. 4
0
 def Deflate(field, wbits=True):
     if wbits:
         CompressedField(field, DeflateStreamWbits)
     else:
         CompressedField(field, DeflateStream)
     return field
Esempio n. 5
0
 def Deflate(field):
     CompressedField(field, DeflateStream)
     return field