wok-next rev 9343
lzma, xz: add lzma --size (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Mar 19 14:47:17 2011 +0100 (2011-03-19) |
parents | 885c330a75ba |
children | 03723f92b911 |
files | lzma/stuff/lzma xz/stuff/lzma |
line diff
1.1 --- a/lzma/stuff/lzma Sat Mar 19 12:43:20 2011 +0100 1.2 +++ b/lzma/stuff/lzma Sat Mar 19 14:47:17 2011 +0100 1.3 @@ -2,7 +2,7 @@ 1.4 1.5 case "$1" in 1.6 d|e|b) exec /usr/bin/lzma-alone $@;; 1.7 ---size) size=$(dd if=$2 bs=1 skip=5 count=8 2> /dev/null | od -t d8 | awk '{ print $2; exit }') 1.8 +--size) size=$(od -t d8 -j5 -N8 < $2 | awk '{ print $2; exit }') 1.9 if [ $size -eq -1 ]; then 1.10 size=$(unlzma -c $2 | wc -c) 1.11 n=$size
2.1 --- a/xz/stuff/lzma Sat Mar 19 12:43:20 2011 +0100 2.2 +++ b/xz/stuff/lzma Sat Mar 19 14:47:17 2011 +0100 2.3 @@ -78,6 +78,15 @@ 2.4 exit 2.5 } 2.6 2.7 +fix_size() 2.8 +{ 2.9 + n=$1 2.10 + for i in $(seq 1 8); do 2.11 + printf '\\\\x%02X' $(($n & 255)) 2.12 + n=$(($n >> 8)) 2.13 + done | xargs echo -en | dd of=$2 conv=notrunc bs=1 seek=5 2> /dev/null 2.14 +} 2.15 + 2.16 case "$0" in 2.17 *unlzma) lzma_utils -d $@ ;; 2.18 *lzcat) lzma_utils -c -d $@ ;; 2.19 @@ -86,14 +95,10 @@ 2.20 # First look if help is needed. 2.21 case "$1" in 2.22 --version|-V|--help|-h|-\?|'') usage;; 2.23 ---size) size=$(dd if=$2 bs=1 skip=5 count=8 2> /dev/null | od -t d8 | awk '{ print $2; exit }') 2.24 +--size) size=$(od -t d8 -j5 -N8 < $2 | awk '{ print $2; exit }') 2.25 if [ $size -eq -1 ]; then 2.26 size=$(unlzma -c $2 | wc -c) 2.27 - n=$size 2.28 - for i in $(seq 1 8); do 2.29 - printf '\\\\x%02X' $(($n & 255)) 2.30 - n=$(($n >> 8)) 2.31 - done | xargs echo -en | dd of=$2 conv=notrunc bs=1 seek=5 2> /dev/null 2.32 + fix_size $size $2 2.33 fi 2.34 echo $size 2.35 exit ;; 2.36 @@ -128,14 +133,6 @@ 2.37 2.38 # fake lzma_alone (-eos -mt1) 2.39 eval xz $args --format=lzma --$mode$extra --stdout $input $output || usage error 2.40 -if [ -n "$input" -a -n "$output" ]; then 2.41 - size=$(stat -c "%s" ${input#< }) 2.42 - ascii="00000 " 2.43 - for i in 1 2 3 4 5 6 7 8; do 2.44 - ascii="$ascii $(printf "%02x" $((size % 256)) )" 2.45 - size=$(( $size / 256 )) 2.46 - done 2.47 - echo "$ascii | .." | hexdump -R | \ 2.48 - dd of=${output#> } seek=5 bs=1 conv=notrunc 2> /dev/null 2.49 -fi 2.50 +[ -n "$input" -a -n "$output" ] && 2.51 + fix_size $(stat -c "%s" ${input#< }) ${output#> } 2.52 exit 0