Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

fcopy with Trf zip

14 views
Skip to first unread message

vitic

unread,
May 8, 2008, 12:48:50 AM5/8/08
to
#I am trying to an inline compressing with Trf's zip command and
fcopy, like this:

###################################################
package require Trf

set in [open file1]
set out [open file2 w]

set in [zip -attach $fp -mode compress ]

fcopy $in $out

#Error: error reading "file4": invalid argument

#Tried doing this way:
zip -in $in -out $out -mode compress
fcopy $in $out

#It returns 0 and doesn't do anything.
#doesn't work with [read $in] either
####################################################

Has anyone tried this before? Am I doing it wrong?

Thanks,

---Victor

vitic

unread,
May 9, 2008, 4:13:56 PM5/9/08
to

#Well, it looks like not too many people use Trf, I decided to go with
an external solution instead.

set in [open "|gzip -c -q -9 myfile"]
set out [open myoutfile w]
fcopy $in $out

#This works very well but, unfortunately, is not portable across
different OSes.


---Victor

Andreas Kupries

unread,
May 9, 2008, 10:04:51 PM5/9/08
to
vitic <vit...@gmail.com> writes:

> #Well, it looks like not too many people use Trf, I decided to go with
> an external solution instead.

I actually had send a response yesterday, however it seems as if
google groups (the site I posted through) swallowed it.

Let me see if I can reconstruct it.

> On May 7, 9:48 pm, vitic <vit...@gmail.com> wrote:
>> #I am trying to an inline compressing with Trf's zip command and
>> fcopy, like this:
>>
>> ###################################################
>> package require Trf
>>
>> set in [open file1]
>> set out [open file2 w]
>>
>> set in [zip -attach $fp -mode compress ]

First, why are you attaching to $fp, instead of $out ?
From the example 'fp' likely contains a completely unrelated channel.

Second, the result of the 'zip -attach' is the channel you attached
to, so you are additionally overwriting 'in' with something unknown.
I recommend to simply get rid of the assignment.

>> fcopy $in $out
>>
>> #Error: error reading "file4": invalid argument

This is likey what you had in 'fp', an unrelated channel, already closed.

>> #Tried doing this way:
>> zip -in $in -out $out -mode compress
>> fcopy $in $out

>> #It returns 0 and doesn't do anything.

In this mode the zip -in -out has already copied and compressed
everything, leaving nothing for the fcopy to do, hence the 0 zero
result you see. Close in and out, and then look at the file.

>> #doesn't work with [read $in] either

Can't say anything about this, not enough code in the message to make
even a guess about what went wrong in this third attempt.


>> ####################################################
>>
>> Has anyone tried this before? Am I doing it wrong?
>>
>> Thanks,
>>
>> ---Victor
>
>

> set in [open "|gzip -c -q -9 myfile"]
> set out [open myoutfile w]
> fcopy $in $out
>
> #This works very well but, unfortunately, is not portable across
> different OSes.
>
>
> ---Victor

--
So long,
Andreas Kupries <akup...@shaw.ca>
<http://www.purl.org/NET/akupries/>
Developer @ <http://www.activestate.com/>
-------------------------------------------------------------------------------

vitic

unread,
May 10, 2008, 9:42:36 AM5/10/08
to
Thanks a lot Andreas, works flawlessly. Also, thanks for creating
Trf.

For the benefit of anyone who might want to implement this, you also
need to set up your file channels, as in:

fconfigure $in -translation binary
fconfigure $out -translation binary

Otherwise the data will be corrupted.

---Victor

Andreas Kupries

unread,
May 10, 2008, 11:04:50 PM5/10/08
to
vitic <vit...@gmail.com> writes:

Right. I sort of skipped over that in your example. There are some
more things to look out for. The relevant wiki page is

http://wiki.tcl.tk/1180

vitic

unread,
May 12, 2008, 5:02:39 PM5/12/08
to
On May 10, 8:04 pm, Andreas Kupries <akupr...@shaw.ca> wrote:
> vitic <vit...@gmail.com> writes:
> > Thanks a lot Andreas, works flawlessly. Also, thanks for creating
> > Trf.
>
> > For the benefit of anyone who might want to implement this, you also
> > need to set up your file channels, as in:
>
> > fconfigure $in -translation binary
> > fconfigure $out -translation binary
>
> > Otherwise the data will be corrupted.
>
> Right. I sort of skipped over that in your example. There are some
> more things to look out for. The relevant wiki page is
>
>        http://wiki.tcl.tk/1180
>
> --
> So long,
>         Andreas Kupries <akupr...@shaw.ca>

>                         <http://www.purl.org/NET/akupries/>
>         Developer @     <http://www.activestate.com/>
> ---------------------------------------------------------------------------­----

Thanks,

---Victor

0 new messages