Lazarus

Programming => General => Topic started by: dcelso on February 07, 2013, 01:55:34 am

Title: read and save zip files
Post by: dcelso on February 07, 2013, 01:55:34 am
Hello to all, I would like know the differents alternatives to open zip files and if lazarus have official support to this.

I need to open and save a zipped file with have compressesd with simple format zip ( one file inside zip that uses the same name that the zip)

Title: Re: read and save zip files
Post by: BigChimp on February 07, 2013, 08:13:47 am
There's built in zip support. See the wiki:
http://wiki.lazarus.freepascal.org/paszlib

Example of use on the page; I've used it succesfully in my CheckRide open source program (see repository below); many others used it, too.
Title: Re: read and save zip files
Post by: dcelso on February 07, 2013, 09:45:17 am
thanks, I read it before.
But I would like use zip like a Stream. Some like
szip : = tzipstream.create(filename)
szip.read(mypbyte,mylenght);
szip.free;

and after do similar to save

szip : = tzipstream.create(filename)
szip.write(mypbyte,mylenght);
szip.free;

Is there possible with paszlib?
Title: Re: read and save zip files
Post by: BigChimp on February 07, 2013, 10:13:51 am
Yes, AFAIR I used streams in checkride.
Title: Re: read and save zip files
Post by: dcelso on February 07, 2013, 01:58:36 pm
thanks, but i read all your .pas files from https://bitbucket.org/reiniero/checkride/, without find an example of use zlib as I put before.
¿Can you adapt this code to use paszlib?
Title: Re: read and save zip files
Post by: BigChimp on February 07, 2013, 02:18:57 pm
I'd suggest you go through the paszlib/zipper source code.
Title: Re: read and save zip files
Post by: User137 on February 07, 2013, 03:47:08 pm
Do you need it specifically in ZIP format, or is any compression ok? If any is fine, i'd suggest also checking TCompressionStream and TDeCompressionStream.

Zip format might not be that simple... There should be a reason, why apps like Winzip have to decompress the whole file first, if they want to add more files to it, or maybe even if they only want to read 1 file from it. In short it could a complete mess, compared to clear structure you could make to your own file format. Those streams should pack as tight as ZIP anyway.
Title: Re: read and save zip files
Post by: dcelso on February 07, 2013, 06:43:33 pm
umm, I need open zipfiles compressed with standard gzip as this example

gzip -nc  file_in.txt > file_out.gz   (no named file)

The Idea is do transparent to the end user the compression of the generated files with the program, so the end user unknow if the created custom fileformat of my program is compressed or dont, because he can open and save the custom genetated files of my program unknowing it internal contend.
Y need use the same compress method that gzip uses in the command before, because my application would open and save the file-format of the other existing application that do it, or compres and uncompress using gzip common tools.
Title: Re: read and save zip files
Post by: BigChimp on February 07, 2013, 07:12:38 pm
Ok, just to make it clear: gzip and zip are two different formats..
Title: Re: read and save zip files
Post by: dcelso on February 07, 2013, 07:54:47 pm
 :o, yes, then, what do i need?
Title: Re: read and save zip files
Post by: User137 on February 07, 2013, 08:07:31 pm
It seems that gzip only supports 1 file in it. So *nix pack multiple files into .tar first, and then gzip. So you need to decide which one you are after: tar+gzip, or zip? You can use windows-like zip on linux too.
http://superuser.com/questions/334827/how-to-gzip-multiple-files-into-one-gz-file
Title: Re: read and save zip files
Post by: dcelso on February 07, 2013, 08:37:55 pm
exactly, i dont want multiple files into it. If you read the entire post you can understand it.
i need exacly the same that do

gzip -nc fileungzipped > filegzipped.gz

and the contrary

gzip -dc filegzipped.gz > fileunfzipped


an example of use would be like a tfilestream,create but instead of read from a uncompressed file read from a gzipped file directly.

In Java I do it exactly that I say,(using gzipinputstream (http://docs.oracle.com/javase/1.4.2/docs/api/java/util/zip/GZIPInputStream.html)) but I need do the same in lazarus :D.
Title: Re: read and save zip files
Post by: BigChimp on February 07, 2013, 09:21:03 pm
IIIRC, paszlib supports streams... Why dont you look up the source code in the fpc source directory.

I think perhaps the example program for paszlib may use streams but am not sure.
Title: Re: read and save zip files
Post by: dcelso on February 07, 2013, 10:24:20 pm
 :o. Thanks so much. I will study it
Title: Re: read and save zip files
Post by: BigChimp on February 09, 2013, 09:22:06 am
Mmm, had some time to look myself. Seems there's quite some low level paszlib stuff where at least streams are used.

Haven't been able to find higher level example programs using streams...

Hope you found something!
TinyPortal © 2005-2018