2012-06-25 12:49:39 +00:00
|
|
|
#ifndef NALL_STREAM_ZIP_HPP
|
|
|
|
#define NALL_STREAM_ZIP_HPP
|
|
|
|
|
|
|
|
#include <nall/zip.hpp>
|
2012-04-24 13:13:42 +00:00
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
|
|
|
struct zipstream : memorystream {
|
2012-06-25 12:49:39 +00:00
|
|
|
using stream::read;
|
|
|
|
using stream::write;
|
|
|
|
|
|
|
|
zipstream(const stream &stream, const string &filter = "*") {
|
2012-04-24 13:13:42 +00:00
|
|
|
unsigned size = stream.size();
|
|
|
|
uint8_t *data = new uint8_t[size];
|
|
|
|
stream.read(data, size);
|
|
|
|
|
|
|
|
zip archive;
|
|
|
|
if(archive.open(data, size) == false) return;
|
|
|
|
delete[] data;
|
|
|
|
|
|
|
|
for(auto &file : archive.file) {
|
|
|
|
if(file.name.wildcard(filter)) {
|
|
|
|
archive.extract(file, pdata, psize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-25 12:49:39 +00:00
|
|
|
~zipstream() {
|
2012-04-24 13:13:42 +00:00
|
|
|
if(pdata) delete[] pdata;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|