eric6/HexEdit/HexEditChunks.py

changeset 8143
2c730d5fd177
parent 7923
91e843545d9a
child 8207
d359172d11be
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
31 31
32 When HexEditWidget loads data, HexEditChunks access them using a QIODevice 32 When HexEditWidget loads data, HexEditChunks access them using a QIODevice
33 interface. When the app uses a QByteArray or Python bytearray interface, 33 interface. When the app uses a QByteArray or Python bytearray interface,
34 QBuffer is used to provide again a QIODevice like interface. No data will 34 QBuffer is used to provide again a QIODevice like interface. No data will
35 be changed, therefore HexEditChunks opens the QIODevice in 35 be changed, therefore HexEditChunks opens the QIODevice in
36 QIODevice.ReadOnly mode. After every access HexEditChunks closes the 36 QIODevice.OpenModeFlag.ReadOnly mode. After every access HexEditChunks
37 QIODevice. That's why external applications can overwrite files while 37 closes the QIODevice. That's why external applications can overwrite
38 HexEditWidget shows them. 38 files while HexEditWidget shows them.
39 39
40 When the the user starts to edit the data, HexEditChunks creates a local 40 When the the user starts to edit the data, HexEditChunks creates a local
41 copy of a chunk of data (4 kilobytes) and notes all changes there. Parallel 41 copy of a chunk of data (4 kilobytes) and notes all changes there. Parallel
42 to that chunk, there is a second chunk, which keeps track of which bytes 42 to that chunk, there is a second chunk, which keeps track of which bytes
43 are changed and which are not. 43 are changed and which are not.
72 @type QIODevice 72 @type QIODevice
73 @return flag indicating successful operation 73 @return flag indicating successful operation
74 @rtype bool 74 @rtype bool
75 """ 75 """
76 self.__ioDevice = ioDevice 76 self.__ioDevice = ioDevice
77 ok = self.__ioDevice.open(QIODevice.ReadOnly) 77 ok = self.__ioDevice.open(QIODevice.OpenModeFlag.ReadOnly)
78 if ok: 78 if ok:
79 # open successfully 79 # open successfully
80 self.__size = self.__ioDevice.size() 80 self.__size = self.__ioDevice.size()
81 self.__ioDevice.close() 81 self.__ioDevice.close()
82 else: 82 else:
117 if maxSize < 0: 117 if maxSize < 0:
118 maxSize = self.__size 118 maxSize = self.__size
119 elif (pos + maxSize) > self.__size: 119 elif (pos + maxSize) > self.__size:
120 maxSize = self.__size - pos 120 maxSize = self.__size - pos
121 121
122 self.__ioDevice.open(QIODevice.ReadOnly) 122 self.__ioDevice.open(QIODevice.OpenModeFlag.ReadOnly)
123 123
124 while maxSize > 0: 124 while maxSize > 0:
125 chunk.absPos = sys.maxsize 125 chunk.absPos = sys.maxsize
126 chunksLoopOngoing = True 126 chunksLoopOngoing = True
127 while chunkIdx < len(self.__chunks) and chunksLoopOngoing: 127 while chunkIdx < len(self.__chunks) and chunksLoopOngoing:
183 """ 183 """
184 if count == -1: 184 if count == -1:
185 # write all data 185 # write all data
186 count = self.__size 186 count = self.__size
187 187
188 ok = ioDevice.open(QIODevice.WriteOnly) 188 ok = ioDevice.open(QIODevice.OpenModeFlag.WriteOnly)
189 if ok: 189 if ok:
190 idx = pos 190 idx = pos
191 while idx < count: 191 while idx < count:
192 data = self.data(idx, self.BUFFER_SIZE) 192 data = self.data(idx, self.BUFFER_SIZE)
193 ioDevice.write(QByteArray(data)) 193 ioDevice.write(QByteArray(data))
432 432
433 if foundIdx == -1: 433 if foundIdx == -1:
434 newChunk = HexEditChunk() 434 newChunk = HexEditChunk()
435 readAbsPos = absPos - ioDelta 435 readAbsPos = absPos - ioDelta
436 readPos = readAbsPos & self.READ_CHUNK_MASK 436 readPos = readAbsPos & self.READ_CHUNK_MASK
437 self.__ioDevice.open(QIODevice.ReadOnly) 437 self.__ioDevice.open(QIODevice.OpenModeFlag.ReadOnly)
438 self.__ioDevice.seek(readPos) 438 self.__ioDevice.seek(readPos)
439 newChunk.data = bytearray(self.__ioDevice.read(self.CHUNK_SIZE)) 439 newChunk.data = bytearray(self.__ioDevice.read(self.CHUNK_SIZE))
440 self.__ioDevice.close() 440 self.__ioDevice.close()
441 newChunk.absPos = absPos - (readAbsPos - readPos) 441 newChunk.absPos = absPos - (readAbsPos - readPos)
442 newChunk.dataChanged = bytearray(len(newChunk.data)) 442 newChunk.dataChanged = bytearray(len(newChunk.data))

eric ide

mercurial