[Python-es] zipfile Buffered

Andrey Antoukh andsux en gmail.com
Sab Ene 22 12:11:29 CET 2011


El día 22 de enero de 2011 11:45, Juan de Dios Manjón Pérez
<juande en jdmanjon.net> escribió:
> Mi objetivo es manipular ficheros zip sin  tener que extraer a un temp y sin
> tener que leer todo de golpe con readstring = zin.read(item.filename)
>
Bueno, en el ejemplo que muestras, no estas leyendo todo de golpe, si
no que por trocitos de tamaño que esta definido en
io.DEFAULT_BUFFER_SIZE. Por lo que si no me equivoco, el mismo ejemplo
ya hace justo lo que pides.

Creo que si has tenido que escribir 2 veces el mismo mensaje, para que
te responda alguien creo que deberías de mirar si la pregunta que has
hecho es la adecuada.

Un saludo.


> Y el motivo es claro: quiero trabajar con ficheros zip con entradas de gran
> tamaño.
>
> Se me fué la indentación en el for:
>
> BUFFER_SIZE = io.DEFAULT_BUFFER_SIZE¶
>
> zin = zipfile.ZipFile ('archive.zip', 'r')
> zout = zipfile.ZipFile ('archve_new.zip', 'w')
>
> for item in zin.infolist():
>     reader = zin.BufferedReader(item.filename, BUFFER_SIZE)
>     writer = zout.BufferedWriter(item.filename, BUFFER_SIZE)
>     chuck = reader.read(BUFFER_SIZE)
>     while chuck:
>         writer.write(chuck)
>         chuck = reader.read(BUFFER_SIZE)
>     reader.close()
>     writer.close()
>
> zin.close()
> zout.close()
>
>
> A ver si alguien tiene información de como implementarlo......
>
> Saludos
> Juande
>
> El 21/01/2011 14:10, Juan de Dios Manjón Pérez escribió:
>
> BUFFER_SIZE = io.DEFAULT_BUFFER_SIZE¶
>
> zin = zipfile.ZipFile ('archive.zip', 'r')
>
> zout = zipfile.ZipFile ('archve_new.zip', 'w')
>
> for item in zin.infolist():
>     reader = zin.BufferedReader(item.filename, BUFFER_SIZE)
>     writer = zout.BufferedWriter(item.filename, BUFFER_SIZE)
>
> chuck = reader.read(BUFFER_SIZE)
> while chuck:
>      writer.write(chuck)
>      chuck = reader.read(BUFFER_SIZE)
>
> reader.close()
> writer.close()
>
> _______________________________________________
> Python-es mailing list
> Python-es en python.org
> http://mail.python.org/mailman/listinfo/python-es
> FAQ: http://python-es-faq.wikidot.com/
>
>



-- 
http://twitter.com/andsux
http://www.niwi.be
****
http://www.freebsd.org/
http://www.postgresql.org/
http://www.python.org/
http://www.djangoproject.com/

"Linux is for people who hate Windows, BSD is for people who love UNIX"
"Social Engineer -> Because there is no patch for human stupidity"


Más información sobre la lista de distribución Python-es