#!/bin/bash
# Nullpress! - Compress/extract to/from 0 bytes!
# Your filesystem restrictions apply.
# markus@taisia.fi - Patent pending!

syntax() 
{
  echo "Usage : "
  echo -e "$0 c <filename> \t - Compress file"
  echo -e "$0 e <filename> \t - Extract file"
  exit  
}

if [ $# != 2 ]
then
 syntax
fi

# Compress
if [ $1 == "c" ]
then
  echo "Compressing ..."
  touch `cat $2|gzip -|base64|tr '/' '_'|tr -d '\n'`.npz
fi

# Extract
if [ $1 == "e" ]
then
  echo $2|tail -c 5|grep ".npz" > /dev/null

  if [ $? != 0 ]
  then
    echo "Not an NPZ file!"
    exit
  fi

  echo "Extracting to stdout ..."
  echo ${2%.npz}|tr '_' '/'|base64 -d -|gunzip - 
fi
