#System: ArchLinux (up-to-date) on x86_64 tar: GNU tar 1.35 gzip 1.13 # Steps to reproduce: 1. Get/create a compressed archive (e.g. "tar cfz test.tar.gz /etc/xdg") 2. Check it can be read and handled by tar (e.g. "tar tvf test.tar.gz") 3. Try to handle it from stdin (e.g. "tar tvf - < test.tar.gz")
# Actual result: tar cannot select the proper compression tool/library and thus cannot be used in a shell pipeline. $ tar tvf - < test.tar.gz tar: Archive is compressed. Use -z option tar: Error is not recoverable: exiting now # Expected result: Same as step no.2 # Possible Rational TAR normally reads from the archive file a few blocks to understand whether any compression tool/library is needed. It likely "rewinds" the read pointer to the beginning and enables the needed tool/library. TAR doesn't follow the same path when reading from STDIN. I can imagine preview bytes are not pushed back in the buffers for later processing. But this can be done in a number of different ways like moving the preview bytes in the buffer to be used by the handling functions. The statements in the documentation chapter 8.1.1 (Creating and Reading Compressed Archives) can be considered incorrect when not false: you never read directly from any device or pipeline as you likely place those bytes in some memory buffer for later handling. Smart management of those buffer can lead to the solution of the problem. # Disclaimer I could not yet find enough time to analyze current source code.