kubo / snzip

Snzip, a compression/decompression tool based on snappy
Other
217 stars 30 forks source link

behavior of stdin with uncompressing #4

Closed masahif closed 11 years ago

masahif commented 11 years ago

Behaviour of snzip is difference with other same kind command such as bzip2 or gzip.

$ cat test.txt.bz2 | bzip2 -d
foo bar baz

$ cat test.txt.sz | ./snzip -d  # different behaviour!!!
I won't write compressed data to a terminal.
For help, type: 'snzip -h'.

When the command use with stdin, only snzip complain.

kubo commented 11 years ago

"cat file.tar.snz | snzcat > file.tar" works for me without your fix. What OS and compiler do you use? IMO, isatty() is broken on your platform.

kubo commented 11 years ago

What terminal do you use? for example

As far as I tested, Emacs EShell mode is a only terminal where isatty() doesn't work correctly.

masahif commented 11 years ago

I've checked it again and I think my patch is not also enough to fix.

I'm using gnome-terminal and iTerm on Mac10.8.3. Tested following on Mac10.8.3. and CentOS6.3, both returned same result.

$ ./snzip I won't write compressed data to a terminal. For help, type: 'snzip -h'.

$ ./snzip file.tar

$ cat file.tar.sz | ./snzip -dc >file.tar

$ cat file.tar.sz | ./snzip -dc | cat > file.tar

$ cat file.tar.sz | ./snzip -dc | less

$ cat file.tar.sz | ./snzip -dc I won't write compressed data to a terminal. For help, type: 'snzip -h'.

kubo commented 11 years ago

I'll accept your pull request by another reason.

I noticed that both gzip and bzip2 didn't complain when they wrote uncompressed data to stdout as follows.

$ echo foo bar baz > test.txt
$ cat test.txt | gzip
gzip: compressed data not written to a terminal. Use -f to force compression.
For help, type: gzip -h
$ gzip test.txt 
$ cat test.txt.gz | gzip -d
foo bar baz
$ echo foo bar baz > test.txt
$ cat test.txt | bzip2
bzip2: I won't write compressed data to a terminal.
bzip2: For help, type: `bzip2 --help'.
$ bzip2 test.txt 
$ cat test.txt.bz2 | bzip2 -d
foo bar baz

On the other hand,

$ echo foo bar baz > test.txt
$ cat test.txt | ./snzip   # same behaviour with gzip and bzip2.
I won't write compressed data to a terminal.
For help, type: 'snzip -h'.
$ ./snzip test.txt 
$ cat test.txt.sz | ./snzip -d  # different behaviour!!!
I won't write compressed data to a terminal.
For help, type: 'snzip -h'.

Your patch fixes the difference. However the commit message "Following way didn't work and fix it" isn't proper. Could you change the message and push it to this pull request or, if necessary, make a new pull request? Otherwise, can I commit it by myself?

masahif commented 11 years ago

Yes, I'd point out like your comment. Sorry for my irrelevance explaining.

I've changed my first comment.