Exemplo n.º 1
0
    def writeToFile(self, fileobj):

        # Truncate file
        fileobj.seek(0)
        fileobj.truncate()

        # Scene index table will be rebuilt
        self.sceneIndexTable = []

        sceneIndex = 0
        numScenes = len(self.sceneData)

        # Process all scenes
        block = ""
        pointers = []
        firstIndexInBlock = 0

        while True:
            writeBlock = False

            if sceneIndex >= numScenes:

                # All scenes done, write the last block
                cmpData = None
                writeBlock = True

            else:

                # Compress next scene
                cmpData = ff7.compressGzip(self.sceneData[sceneIndex])
                if len(cmpData) % 4 != 0:
                    cmpData += '\xff' * (4 - len(cmpData) % 4
                                         )  # pad scene to 4-byte boundary

                if self.pointerTableSize + len(block) + len(
                        cmpData) > self.blockSize:

                    # Scene doesn't fit in current block, write it first
                    writeBlock = True

            if writeBlock:

                # Write current block to file
                for p in pointers:
                    fileobj.write(struct.pack("<L", p >> 2))
                for i in xrange(16 - len(pointers)):
                    fileobj.write(struct.pack("<L", 0xffffffff))

                if len(block) < self.blockSize - self.pointerTableSize:
                    block += '\xff' * (self.blockSize - self.pointerTableSize -
                                       len(block))  # pad with 0xff bytes

                fileobj.write(block)

                self.sceneIndexTable.append(firstIndexInBlock)

                block = ""
                pointers = []
                firstIndexInBlock = sceneIndex

            if sceneIndex >= numScenes:

                # All done
                break

            else:

                # Add compressed scene to block
                pointers.append(len(block) + self.pointerTableSize)
                block += cmpData

                sceneIndex += 1
Exemplo n.º 2
0
    def writeToFile(self, fileobj):

        # Truncate file
        fileobj.seek(0)
        fileobj.truncate()

        # Scene index table will be rebuilt
        self.sceneIndexTable = []

        sceneIndex = 0
        numScenes = len(self.sceneData)

        # Process all scenes
        block = ""
        pointers = []
        firstIndexInBlock = 0

        while True:
            writeBlock = False

            if sceneIndex >= numScenes:

                # All scenes done, write the last block
                cmpData = None
                writeBlock = True

            else:

                # Compress next scene
                cmpData = ff7.compressGzip(self.sceneData[sceneIndex])
                if len(cmpData) % 4 != 0:
                    cmpData += '\xff' * (4 - len(cmpData) % 4)  # pad scene to 4-byte boundary

                if self.pointerTableSize + len(block) + len(cmpData) > self.blockSize:

                    # Scene doesn't fit in current block, write it first
                    writeBlock = True

            if writeBlock:

                # Write current block to file
                for p in pointers:
                    fileobj.write(struct.pack("<L", p >> 2))
                for i in xrange(16 - len(pointers)):
                    fileobj.write(struct.pack("<L", 0xffffffff))

                if len(block) < self.blockSize - self.pointerTableSize:
                    block += '\xff' * (self.blockSize - self.pointerTableSize - len(block))  # pad with 0xff bytes

                fileobj.write(block)

                self.sceneIndexTable.append(firstIndexInBlock)

                block = ""
                pointers = []
                firstIndexInBlock = sceneIndex

            if sceneIndex >= numScenes:

                # All done
                break

            else:

                # Add compressed scene to block
                pointers.append(len(block) + self.pointerTableSize)
                block += cmpData

                sceneIndex += 1
Exemplo n.º 3
0
 def setData(self, data):
     self.rawDataSize = len(data)
     self.cmpData = ff7.compressGzip(data)