How to write a ziparchive to disk correctly?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to write a ziparchive to disk correctly?

Johan Brichau-2
Hi all,

Does anyone have experience manipulating zipfiles in GS?

I'm struggling to write out a ZipArchive back to disk. Somehow, the zipfile is not correct (unzip complains that bytes are missing and possibly the data was not created in binary mode). Although, in the end unzip manages to unzip it. However, that's not good enough in my case.  I got everything running fine in Pharo but get stuck here...

The zipfile itself was read from disk and seems to be decoding just fine. I can read out the correct files, etc...
Then, just writing it back to disk as follows, is not giving me a correct zipfile.
(archive is an instance of ZipArchive).

        file := GsFile open: 'foo.zip' mode:'wb' onClient: false
        stream := RWBinaryOrTextStream on: ByteArray new.
        stream binary.
        archive writeTo: stream. stream reset.
        file nextPutAll: stream contents.
        file close.

Any ideas are appreciated!

Johan
Reply | Threaded
Open this post in threaded view
|

Re: How to write a ziparchive to disk correctly?

Paul DeBruicker
Monticello files are zip files with the extension renamed from zip to mcz. Maybe there's something in the Monticello code you could follow.




On Feb 22, 2011, at 8:30 PM, Johan Brichau <[hidden email]> wrote:

> Hi all,
>
> Does anyone have experience manipulating zipfiles in GS?
>
> I'm struggling to write out a ZipArchive back to disk. Somehow, the zipfile is not correct (unzip complains that bytes are missing and possibly the data was not created in binary mode). Although, in the end unzip manages to unzip it. However, that's not good enough in my case.  I got everything running fine in Pharo but get stuck here...
>
> The zipfile itself was read from disk and seems to be decoding just fine. I can read out the correct files, etc...
> Then, just writing it back to disk as follows, is not giving me a correct zipfile.
> (archive is an instance of ZipArchive).
>
>    file := GsFile open: 'foo.zip' mode:'wb' onClient: false
>    stream := RWBinaryOrTextStream on: ByteArray new.
>    stream binary.
>    archive writeTo: stream. stream reset.
>    file nextPutAll: stream contents.
>    file close.
>
> Any ideas are appreciated!
>
> Johan
Reply | Threaded
Open this post in threaded view
|

Re: How to write a ziparchive to disk correctly?

Dale Henrichs
In reply to this post by Johan Brichau-2
Johan,

Not sure where the bug is for this particular problem ... GemStone
Streams manage the position instance variable differently then Squeak,
so when I ported ZipArchive code, I had to fiddle with a number of spots
that were using position ... I obviously got things to the point where
the ZipArchive code is happy and things work for Monticello, but I must
have missed at least one spot that was only used by non-Smalltalk zip
implmentations:)

We had this problem reported internally (Bug 38576) and according to the
report:

   unzip reports "missing 1 bytes"

But since monticello was happy, I never tracked it down. I guess it's
time to bite the bullet.

Dale
On 02/22/2011 05:30 PM, Johan Brichau wrote:

> Hi all,
>
> Does anyone have experience manipulating zipfiles in GS?
>
> I'm struggling to write out a ZipArchive back to disk. Somehow, the zipfile is not correct (unzip complains that bytes are missing and possibly the data was not created in binary mode). Although, in the end unzip manages to unzip it. However, that's not good enough in my case.  I got everything running fine in Pharo but get stuck here...
>
> The zipfile itself was read from disk and seems to be decoding just fine. I can read out the correct files, etc...
> Then, just writing it back to disk as follows, is not giving me a correct zipfile.
> (archive is an instance of ZipArchive).
>
> file := GsFile open: 'foo.zip' mode:'wb' onClient: false
> stream := RWBinaryOrTextStream on: ByteArray new.
> stream binary.
> archive writeTo: stream. stream reset.
> file nextPutAll: stream contents.
> file close.
>
> Any ideas are appreciated!
>
> Johan

Reply | Threaded
Open this post in threaded view
|

Re: How to write a ziparchive to disk correctly?

Dale Henrichs
In reply to this post by Johan Brichau-2
On 02/22/2011 05:30 PM, Johan Brichau wrote:

> Hi all,
>
> Does anyone have experience manipulating zipfiles in GS?
>
> I'm struggling to write out a ZipArchive back to disk. Somehow, the zipfile is not correct (unzip complains that bytes are missing and possibly the data was not created in binary mode). Although, in the end unzip manages to unzip it. However, that's not good enough in my case.  I got everything running fine in Pharo but get stuck here...
>
> The zipfile itself was read from disk and seems to be decoding just fine. I can read out the correct files, etc...
> Then, just writing it back to disk as follows, is not giving me a correct zipfile.
> (archive is an instance of ZipArchive).
>
> file := GsFile open: 'foo.zip' mode:'wb' onClient: false
> stream := RWBinaryOrTextStream on: ByteArray new.
> stream binary.
> archive writeTo: stream. stream reset.
> file nextPutAll: stream contents.
> file close.
>
> Any ideas are appreciated!
>
> Johan

Would you give this change to ZipArchive>>writeTo: a try ... it fixes
the unzip complaints for the mcz files that I've tested...

Dale
Reply | Threaded
Open this post in threaded view
|

Re: How to write a ziparchive to disk correctly?

Dale Henrichs
On 02/23/2011 10:09 AM, Dale Henrichs wrote:

> On 02/22/2011 05:30 PM, Johan Brichau wrote:
>> Hi all,
>>
>> Does anyone have experience manipulating zipfiles in GS?
>>
>> I'm struggling to write out a ZipArchive back to disk. Somehow, the zipfile is not correct (unzip complains that bytes are missing and possibly the data was not created in binary mode). Although, in the end unzip manages to unzip it. However, that's not good enough in my case.  I got everything running fine in Pharo but get stuck here...
>>
>> The zipfile itself was read from disk and seems to be decoding just fine. I can read out the correct files, etc...
>> Then, just writing it back to disk as follows, is not giving me a correct zipfile.
>> (archive is an instance of ZipArchive).
>>
>> file := GsFile open: 'foo.zip' mode:'wb' onClient: false
>> stream := RWBinaryOrTextStream on: ByteArray new.
>> stream binary.
>> archive writeTo: stream. stream reset.
>> file nextPutAll: stream contents.
>> file close.
>>
>> Any ideas are appreciated!
>>
>> Johan
>
> Would you give this change to ZipArchive>>writeTo: a try ... it fixes
> the unzip complaints for the mcz files that I've tested...
>
> Dale

Woops, here's the code:

writeTo: stream
        members do: [ :member |
                member writeTo: stream.
                member endRead.
        ].
        writeCentralDirectoryOffset := stream position - 1.
        self writeCentralDirectoryTo: stream.

Reply | Threaded
Open this post in threaded view
|

Re: How to write a ziparchive to disk correctly?

Johan Brichau-2
Hi Dale,

That fixes the problem indeed!
I had not noticed the issue on the tracker.

thanks once again!
Johan

On 23 Feb 2011, at 19:51, Dale Henrichs wrote:

> On 02/23/2011 10:09 AM, Dale Henrichs wrote:
>> On 02/22/2011 05:30 PM, Johan Brichau wrote:
>>> Hi all,
>>>
>>> Does anyone have experience manipulating zipfiles in GS?
>>>
>>> I'm struggling to write out a ZipArchive back to disk. Somehow, the zipfile is not correct (unzip complains that bytes are missing and possibly the data was not created in binary mode). Although, in the end unzip manages to unzip it. However, that's not good enough in my case.  I got everything running fine in Pharo but get stuck here...
>>>
>>> The zipfile itself was read from disk and seems to be decoding just fine. I can read out the correct files, etc...
>>> Then, just writing it back to disk as follows, is not giving me a correct zipfile.
>>> (archive is an instance of ZipArchive).
>>>
>>> file := GsFile open: 'foo.zip' mode:'wb' onClient: false
>>> stream := RWBinaryOrTextStream on: ByteArray new.
>>> stream binary.
>>> archive writeTo: stream. stream reset.
>>> file nextPutAll: stream contents.
>>> file close.
>>>
>>> Any ideas are appreciated!
>>>
>>> Johan
>>
>> Would you give this change to ZipArchive>>writeTo: a try ... it fixes
>> the unzip complaints for the mcz files that I've tested...
>>
>> Dale
>
> Woops, here's the code:
>
> writeTo: stream
> members do: [ :member |
> member writeTo: stream.
> member endRead.
> ].
> writeCentralDirectoryOffset := stream position - 1.
> self writeCentralDirectoryTo: stream.
>

Reply | Threaded
Open this post in threaded view
|

Re: How to write a ziparchive to disk correctly?

Dale Henrichs
Oh I added the issue to the tracker after your email:) ... the internal bug had been in existence for awhile, but I didn't add the issue to glassdb until yesterday...

Dale

On Feb 23, 2011, at 11:17 PM, Johan Brichau wrote:

> Hi Dale,
>
> That fixes the problem indeed!
> I had not noticed the issue on the tracker.
>
> thanks once again!
> Johan
>
> On 23 Feb 2011, at 19:51, Dale Henrichs wrote:
>
>> On 02/23/2011 10:09 AM, Dale Henrichs wrote:
>>> On 02/22/2011 05:30 PM, Johan Brichau wrote:
>>>> Hi all,
>>>>
>>>> Does anyone have experience manipulating zipfiles in GS?
>>>>
>>>> I'm struggling to write out a ZipArchive back to disk. Somehow, the zipfile is not correct (unzip complains that bytes are missing and possibly the data was not created in binary mode). Although, in the end unzip manages to unzip it. However, that's not good enough in my case.  I got everything running fine in Pharo but get stuck here...
>>>>
>>>> The zipfile itself was read from disk and seems to be decoding just fine. I can read out the correct files, etc...
>>>> Then, just writing it back to disk as follows, is not giving me a correct zipfile.
>>>> (archive is an instance of ZipArchive).
>>>>
>>>> file := GsFile open: 'foo.zip' mode:'wb' onClient: false
>>>> stream := RWBinaryOrTextStream on: ByteArray new.
>>>> stream binary.
>>>> archive writeTo: stream. stream reset.
>>>> file nextPutAll: stream contents.
>>>> file close.
>>>>
>>>> Any ideas are appreciated!
>>>>
>>>> Johan
>>>
>>> Would you give this change to ZipArchive>>writeTo: a try ... it fixes
>>> the unzip complaints for the mcz files that I've tested...
>>>
>>> Dale
>>
>> Woops, here's the code:
>>
>> writeTo: stream
>> members do: [ :member |
>> member writeTo: stream.
>> member endRead.
>> ].
>> writeCentralDirectoryOffset := stream position - 1.
>> self writeCentralDirectoryTo: stream.
>>
>