Created
October 29, 2017 04:21
-
-
Save isagallerani/b6e14b01a05154f8bbb46d6b66f97ddd to your computer and use it in GitHub Desktop.
Compressso created by isagallerani - https://repl.it/NYCQ/1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#compressao | |
def compressao(): | |
arq = open("arquivo.txt", 'r+') #lendo e depois alterando | |
posicao = 0 | |
fim = 0 | |
encontrou = 0 | |
arq.seek(posicao) | |
while(not encontrou): | |
w = arq.read(TAM_CABECALHO_BLOCO) #le o cabecalho | |
if(w == ""): #arquivo vazio | |
break | |
elif(int(w) > 0): | |
posicao += 1 | |
for i in range(0, int(w)): | |
ra = arq.read(TAM_RA) | |
if(ra[0] == '#'): #encontrou registro que precisa ser removido | |
encontrou = 1 | |
break | |
else: #se nao encontrou, anda mais 100 bytes e vai pro prox registro | |
posicao += TAM_REGISTRO | |
arq.seek(posicao) | |
if((not encontrou) and (int(w) == 5)): | |
posicao += TAM_COMPLEMENTO_BLOCO | |
arq.seek(posicao) | |
if encontrou: | |
arq.seek(posicao) | |
registroRealocado += bloco.Registro(int (w)) #copio o ultimo registro que é o de nro w | |
for i in range(posicao, posicao += TAM_REGISTRO): #TAM_REGISTRO? buguei | |
alteraRegistro[i] += string(registroRealocado[i]) #sobrescreve? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment