def delBuffer(rfile:ReadBinaryFileWithABuffer, wfile:WriteFile, delList:list) : rfile.resetRead() if len(delList) > 0: rfile.resetRead() startStopIndex = delList.pop(0) startIndex = startStopIndex[0] stopIndex = startStopIndex[1] while True: if rfile.getCurrent() >= rfile.file_seek_end: break if startIndex > rfile.getCurrent() + rfile.buffer or rfile.getCurrent() >= stopIndex: wfile.appendByte(data=rfile.read()) else: if rfile.getCurrent() < startIndex: wfile.appendByte(data=readIndexBytes(filename=rfile.filename, startIndex=rfile.getCurrent(), stopIndex=startIndex)) rfile.setCurrent(seek=stopIndex) if len(delList) > 0: startStopIndex = delList.pop(0) startIndex = startStopIndex[0] stopIndex = startStopIndex[1] else: wfile.appendByte(data=rfile.readIndex(stopIndex)) else: rfile.resetRead() while True: bufferData=rfile.read() if bufferData == b'': break wfile.writeByte(bufferData)
def deleteOneIndex(rfile:ReadBinaryFileWithABuffer, wfile:WriteFile, startIndex:int , stopIndex:int) : rfile.resetRead() while True: if rfile.getCurrent() >= rfile.file_seek_end: break if startIndex > rfile.getCurrent()+rfile.buffer or rfile.getCurrent() >= stopIndex: wfile.appendByte( data=rfile.read() ) else: if rfile.getCurrent() < startIndex: wfile.appendByte(data=readIndexBytes(filename=rfile.filename, startIndex=rfile.getCurrent(), stopIndex=startIndex)) wfile.appendByte(data=rfile.readIndex(stopIndex))
def replaceBuffer(rfile:ReadBinaryFileWithABuffer, wfile:WriteFile, searchData:bytes, replaceData:bytes) : result=[] searchData_length= len(searchData) search_counter=0 counter=0 rfile.resetRead() while True: bufferData=rfile.read() if bufferData == b'': break for ii in range(0, len(bufferData)): if bufferData[ii:ii+1] == searchData[search_counter:search_counter+1]: if search_counter == searchData_length-1: result.append( counter-search_counter ) search_counter = 0 else: search_counter += 1 else: search_counter = 0 counter += 1 if len(result) > 0: rfile.resetRead() startIndex = result.pop(0) stopIndex = startIndex + searchData_length while True: if rfile.getCurrent() >= rfile.file_seek_end: break if startIndex > rfile.getCurrent() + rfile.buffer or rfile.getCurrent() >= stopIndex: wfile.appendByte(data=rfile.read()) else: if rfile.getCurrent() < startIndex: wfile.appendByte(data=readIndexBytes(filename=rfile.filename, startIndex=rfile.getCurrent(), stopIndex=startIndex)) wfile.appendByte(data=replaceData) rfile.setCurrent(seek=stopIndex) if len(result)>0: startIndex = result.pop(0) stopIndex = startIndex + searchData_length else: wfile.appendByte(data=rfile.readIndex(stopIndex)) else: rfile.resetRead() while True: bufferData=rfile.read() if bufferData == b'': break wfile.writeByte(bufferData)