Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # uses cat for fast appending of files
- # stat for getting file info
- # xxd for reading byte offsets
- # dd for extracting files fril
- # perhaps stat and dd alone would be more sane
- # a cat archive is a carchive? why not?
- carchive ()
- {
- let offset=0
- STAT="/tmp/stat.tmp"
- [ -f "${STAT}" ] && rm -f "${STAT}"
- CARCHIVE="${1}"
- carext="${CARCHIVE##*.}"
- [ ! "Xcar" == "X${carext}" ] && echo "first paramater should be the archive name: ( <nams>.car )" && exit 1
- shift
- for f in "$@"
- do
- ext="${f##*.}"
- fname="${f%.*}"
- let fsize="$(stat --format='%s' ${f} )"
- let offset="$offset + $fsize"
- cat "$offset" >> "${STAT}"
- stat -t "$f" >> "${STAT}"
- cat "$f" >> /tmp/"$CARCHIVE"
- done
- statfile_size=$(stat --format="%s" "${STAT}")
- cat "${STAT}"
- echo -e "statfile size =\t ${statfile_size} bytes"
- cat "${STAT}" >> "/tmp/${CARCHIVE}"
- echo ${statfile_size} >> "/tmp/${CARCHIVE}"
- cp "/tmp/${CARCHIVE}" .
- }
- test_carchive()
- {
- # get size of file
- let fsize="$(stat --format="%s" "${1}")"
- #go back 2 bytes
- let offset="fsize - 2"
- # get the byte size put there
- let stat_size="$(xxd -l 2 -ps -c 2 -seek $offset ${1} )"
- # scrape off the stat file
- let startofstat="offset - ${stat_size}"
- dd if="${1}" bs=1 skip=${startofstat} count=${stat_size} iflag=skip_bytes,count_bytes of="/tmp/${1}.stat"
- mapfile -t stat_array < "/tmp/${1}.stat"
- for line in stat_array
- do
- echo "${line}"
- read_stat "${line}"
- done
- }
- read_stat()
- {
- # stat -t == --format="%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o"
- # %n name %s size %b blocks %u uid %g gid ....
- while IFS=$' \n' read -r -a stat_info
- do
- offset="${stat_info[0]}"
- >&2 echo "offset = ${offset}"
- name="${stat_info[1]}"
- >&2 echo "name = ${name}"
- size="${stat_info[2]}"
- >&2 echo "size = ${size}"
- # the rest
- for s in "${stat_info[@]"
- do
- >&2 echo -e "${s} "
- done
- >&2 echo -e "\n"
- # output
- echo "${name} ${offset} ${size}"
- }
- uncarchive()
- {
- if [ $# -lt 4 ] ;then
- echo "badly formatted unarchive hint stop stop stop"
- break
- else
- dd if="${1}" bs=1 skip="${2}" count="${3}" iflag=skip_bytes,count_bytes of="${4}"
- echo "unarchived ${4}"
- fi
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement