* * *

Author Topic: read and save zip files  (Read 2620 times)

dcelso

  • Full Member
  • ***
  • Posts: 155
read and save zip files
« 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)


BigChimp

  • Hero Member
  • *****
  • Posts: 5591
  • Add to the wiki - it's free ;)
    • FPCTwit twitter, PaperTiger scanning and other open source projects
Re: read and save zip files
« Reply #1 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.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

dcelso

  • Full Member
  • ***
  • Posts: 155
Re: read and save zip files
« Reply #2 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?

BigChimp

  • Hero Member
  • *****
  • Posts: 5591
  • Add to the wiki - it's free ;)
    • FPCTwit twitter, PaperTiger scanning and other open source projects
Re: read and save zip files
« Reply #3 on: February 07, 2013, 10:13:51 am »
Yes, AFAIR I used streams in checkride.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

dcelso

  • Full Member
  • ***
  • Posts: 155
Re: read and save zip files
« Reply #4 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?

BigChimp

  • Hero Member
  • *****
  • Posts: 5591
  • Add to the wiki - it's free ;)
    • FPCTwit twitter, PaperTiger scanning and other open source projects
Re: read and save zip files
« Reply #5 on: February 07, 2013, 02:18:57 pm »
I'd suggest you go through the paszlib/zipper source code.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

User137

  • Hero Member
  • *****
  • Posts: 1392
    • Nxpascal home
Re: read and save zip files
« Reply #6 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.
Win7, FPC and Lazarus 32-bit SVN version.

dcelso

  • Full Member
  • ***
  • Posts: 155
Re: read and save zip files
« Reply #7 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.

BigChimp

  • Hero Member
  • *****
  • Posts: 5591
  • Add to the wiki - it's free ;)
    • FPCTwit twitter, PaperTiger scanning and other open source projects
Re: read and save zip files
« Reply #8 on: February 07, 2013, 07:12:38 pm »
Ok, just to make it clear: gzip and zip are two different formats..
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

dcelso

  • Full Member
  • ***
  • Posts: 155
Re: read and save zip files
« Reply #9 on: February 07, 2013, 07:54:47 pm »
 :o, yes, then, what do i need?

User137

  • Hero Member
  • *****
  • Posts: 1392
    • Nxpascal home
Re: read and save zip files
« Reply #10 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
Win7, FPC and Lazarus 32-bit SVN version.

dcelso

  • Full Member
  • ***
  • Posts: 155
Re: read and save zip files
« Reply #11 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) but I need do the same in lazarus :D.

BigChimp

  • Hero Member
  • *****
  • Posts: 5591
  • Add to the wiki - it's free ;)
    • FPCTwit twitter, PaperTiger scanning and other open source projects
Re: read and save zip files
« Reply #12 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.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

dcelso

  • Full Member
  • ***
  • Posts: 155
Re: read and save zip files
« Reply #13 on: February 07, 2013, 10:24:20 pm »
 :o. Thanks so much. I will study it

BigChimp

  • Hero Member
  • *****
  • Posts: 5591
  • Add to the wiki - it's free ;)
    • FPCTwit twitter, PaperTiger scanning and other open source projects
Re: read and save zip files
« Reply #14 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!
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus