in = nullptr;
}
+void RawData::write_io(IO::Base &io, bool compress)
+{
+ if(!data)
+ throw logic_error("no data");
+
+ io.write(signature, sizeof(signature));
+
+ for(unsigned i=56; i<64; i-=8)
+ io.put((size>>i)&0xFF);
+
+ uint16_t flags = 0;
+ if(compress)
+ flags |= COMPRESSED;
+ io.put((flags>>8)&0xFF);
+ io.put(flags&0xFF);
+
+ if(compress)
+ {
+ IO::ZlibCompressed z(io, IO::M_WRITE);
+ z.write(data, size);
+ }
+ else
+ io.write(data, size);
+}
+
} // namespace DataFile
} // namespace Msp
#include <msp/datafile/parser.h>
+#include <msp/datafile/rawdata.h>
#include <msp/datafile/statement.h>
#include <msp/datafile/writer.h>
#include <msp/fs/utils.h>
ObjectList objects;
if(detect_data(in))
transfer_datafile(in, fn, *tmp_file, objects);
+ else if(detect_raw(in))
+ transfer_raw_data(in, fn, *tmp_file);
else
transfer_unknown(in, *tmp_file);
return data;
}
+bool Packer::detect_raw(IO::Seekable &in)
+{
+ char header[4] = { };
+ IO::SeekOffset offset = in.tell();
+ in.read(header, sizeof(header));
+ in.seek(offset, IO::S_BEG);
+ return DataFile::RawData::detect_signature(string(header, sizeof(header)));
+}
+
void Packer::transfer_datafile(IO::Base &in, const string &fn, IO::Base &out, ObjectList &objects)
{
DataFile::Parser parser(in, fn);
delete writer;
}
+void Packer::transfer_raw_data(IO::Base &in, const string &fn, IO::Base &out)
+{
+ DataFile::RawData raw;
+ raw.open_io(in, fn);
+ raw.load();
+ raw.write_io(out, tool.is_compressed());
+}
+
void Packer::transfer_unknown(IO::Base &in, IO::Base &out)
{
while(!in.eof())
void pack_file(const std::string &);
private:
bool detect_data(Msp::IO::Seekable &);
+ bool detect_raw(Msp::IO::Seekable &);
void transfer_datafile(Msp::IO::Base &, const std::string &, Msp::IO::Base &, ObjectList &);
+ void transfer_raw_data(Msp::IO::Base &, const std::string &, Msp::IO::Base &);
void transfer_unknown(Msp::IO::Base &, Msp::IO::Base &);
public:
void create_pack(const std::string &);
Msp::IO::Base *open_output(const std::string &);
Msp::IO::Base *open_input(const std::string &);
public:
+ bool is_compressed() const { return compress; }
Msp::DataFile::Writer *create_writer(Msp::IO::Base &);
};