diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-05-20 14:35:59 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2014-05-20 14:35:59 +0100 |
commit | aa7ad950590dffef2a7dc37135c763e9890a5b9e (patch) | |
tree | 3cf5156554d3bd89f86cf4142af0f7a944e110c9 /recv-hole | |
download | xfer-hole-aa7ad950590dffef2a7dc37135c763e9890a5b9e.tar.gz |
Initial commit
Diffstat (limited to 'recv-hole')
-rwxr-xr-x | recv-hole | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/recv-hole b/recv-hole new file mode 100755 index 0000000..cd54233 --- /dev/null +++ b/recv-hole @@ -0,0 +1,41 @@ +#!/bin/sh + +set -eu + + +die() +{ + echo "$@" 1>&2 + exit 1 +} + + +recv_hole() +{ + local n + + read n + truncate --size "+$n" "$1" +} + + +recv_data() +{ + local n + + read n + dd of="$1" conv=notrunc oflag=append bs=1 count="$n" status=noxfer 2>&1 | grep -Ev ' records (in|out)$' || true +} + + +output="$1" + +touch "$output" +while read what +do + case "$what" in + DATA) recv_data "$output" ;; + HOLE) recv_hole "$output" ;; + *) die "Unknown instruction: $what" ;; + esac +done |