2 #include <msp/io/zlibcompressed.h>
3 #include "collection.h"
20 void RawData::open_file(Collection &coll, const string &fn)
23 throw logic_error("input already exists");
25 RefPtr<IO::Base> opened = coll.open_raw(fn);
27 throw IO::file_not_found(fn);
34 void RawData::open_io(IO::Base &i, const string &fn)
37 throw logic_error("input already exists");
40 unsigned len = i.read(header, sizeof(header));
41 if(len!=sizeof(header))
42 throw data_error(fn, 0, "Missing header");
43 if(header[0]!='M' || header[1]!='D' || header[2]!='R' || header[3]!=1)
44 throw data_error(fn, 0, "Bad header");
47 for(unsigned j=0; j<8; ++j)
48 size = (size<<8) | static_cast<unsigned char>(header[4+j]);
50 uint16_t flags = (static_cast<unsigned char>(header[12])<<8) | static_cast<unsigned char>(header[13]);
55 compressed = new IO::ZlibCompressed(*in, IO::M_READ);
61 throw logic_error("no input");
63 throw logic_error("already loaded");
65 owned_data = new char[size];
66 load_into(owned_data);
69 void RawData::load_into(void *buffer)
72 throw logic_error("no input");
74 data = static_cast<char *>(buffer);
76 IO::Base *src = (compressed ? compressed : in);
80 size_t len = src->read(data+pos, size-pos);
82 throw data_error(src_name, 0, "Truncated data");
91 } // namespace DataFile