Note in the code below that by using a multi-format zcat, other data not
in one of the formats supported by the zcat used may be no longer
ignored but passed to cpio (possibly compressed), which may be the cause
of the problem.
Using the compressors directly to test the format (without *zcat
wrappers) guarantees that the "other data" is indeed ignored.
if zcat -t "$archive" >/dev/null 2>&1 ; then
zcat "$archive"
elif xzcat -t "$archive" >/dev/null 2>&1 ; then
xzcat "$archive"
elif lz4cat -t "$archive" >/dev/null 2>&1 ; then
lz4cat "$archive"
elif bzip2 -t "$archive" >/dev/null 2>&1 ; then
bzip2 -c -d "$archive"
elif lzop -t "$archive" >/dev/null 2>&1 ; then
lzop -c -d "$archive"
# Ignoring other data, which may be garbage at the end of the file
fi | (
if [ -n "$dir" ]; then
mkdir -p -- "$dir"
cd -- "$dir"
fi
cpio "$@"
)