read.cpp
Go to the documentation of this file.
00001 #include <megatree/storage_factory.h>
00002 #include <boost/filesystem/operations.hpp>
00003 #include <boost/filesystem/convenience.hpp>
00004 #include <boost/iostreams/device/mapped_file.hpp>
00005 #include <cstdio>
00006 
00007 
00008 int main(int argc, char** argv)
00009 {
00010   if (argc != 3)
00011   {
00012     printf("Usage: ./read tree file\n");
00013     return 0;
00014   }
00015 
00016   std::string tree_path(argv[1]);
00017   std::string filename(argv[2]);
00018   
00019   // read file from storage
00020   printf("reading data from storage\n");
00021   megatree::ByteVec data;
00022   boost::shared_ptr<megatree::Storage> mystorage = megatree::openStorage(tree_path);
00023   mystorage->get(filename, data);
00024 
00025   // write bytevec into file 
00026   printf("writing data to file\n");
00027   boost::iostreams::mapped_file_params params;
00028   params.path = filename;
00029   params.mode = std::ios_base::out;
00030   params.offset = 0;
00031   params.new_file_size = data.size();
00032   boost::iostreams::mapped_file file(params);
00033   memcpy(file.data(), (void*)&data[0], data.size());
00034   file.close();
00035 
00036   return 0;
00037 }


megatree_storage
Author(s): Wim Meeussen
autogenerated on Thu Nov 28 2013 11:30:26