#include "extract.hh"


Extract::Extract (DataSource& ds, std::string name) : 
  ds (ds),
  name (name)
{
}


void Extract::write_file (int64_t start, int64_t length) 
{
  const char* file_name = name.c_str ();

  std::cout << "Output to: " << name << std::endl;

  clear_file (file_name);
  std::ofstream outfile (file_name, std::ostream::binary);
  for (int64_t i = 0; i < length; i++) {
    // std::cout << "write_file: start = " << start << "; length = " << length << "; i = " << i << std::endl;
    outfile << (ds.read (start + i));
  }
  outfile.close ();
}
