#!/usr/bin/env bash
# diff <reference:filename>
# Produces on standard output ed script required to recreate standard input given reference.
here="$(dirname "$0")"
function encode { "$here/bufs" 1 "$here/prefix" <(diff -e <(xxd -p -c 1  < "$1") <(xxd -p -c 1)); }
# function decode { "$here/bufs" 1 "$here/unprefix" <(cat) | patch -e -o >(xxd -r -p -c 1) <(xxd -p -c 1 < "$1"); } 
function decode { ("$here/bufs" 1 "$here/unprefix" <(cat) && echo ,p) | ed -s <(xxd -p -c 1 < "$1") | xxd -r -p -c 1; } 
"$@"
xxd -c 1 -p | xxd -r -c 1 -p 
