#include <string>
#include <iostream>
#include "BitStreams.h"
using namespace std;

// convert a binary file to a '0'/'1' equivalent text file
int main(int argc, char* argv[]) {

  InBitStream ibs;

  string filename;
  if (argc>1) {  // try to find filename as argument
    filename = argv[1];
    ibs.open(filename);
  }

  while (!ibs.isOpen()) {  // in either case, keep going until properly opened
    cout << "Enter input filename: ";
    cout.flush();
    cin >> filename;
    ibs.open(filename);
  }

  // open output file with additional suffix in name
  OutBitStream obs(filename+".view");

  // read input bit-by-bit, writing out characters to output
  while (!ibs.eof()) {
    int bit = ibs.read();             // read single bit
    obs.write((bit ? '1' : '0'), 8);  // write the 8-bit character '0' or '1'
  }


  ibs.close();
  obs.close();
}
