C++ Library to handle BagIt structures. BagIt is a standard format to create transfer packages for digital preservation purposes. See https://en.wikipedia.org/wiki/BagIt for details http://andreas-romeyke.de
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.4 KiB

#include "bag.hpp"
#include "payload.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
Bag::Bag( string dfname ) {
cout << "load constructor (" << dfname << ")" << endl;
// read in file bagit.txt
string bagit_txt_path = dfname + "bagit.txt";
log << "parse " << bagit_txt_path << endl;
ifstream bagit_txt_file;
bagit_txt_file.open( bagit_txt_path );
if (bagit_txt_file.is_open()) {
string version_line;
string utf8_line;
getline(bagit_txt_file, version_line);
getline(bagit_txt_file, utf8_line);
bagit_txt_file.close();
stringstream version_ss ( version_line );
string major;
string minor;
string vprefix;
getline(version_ss, vprefix, ' ');
getline(version_ss, major ,'.');
getline(version_ss, minor, '.');
if (0 != vprefix.compare("BagIt-Version:")) {
log << "wrong vprefix='" << vprefix << "', but 'BagIt-Version:' expected" << endl;
}
cout << "major:'"<<major<<"'"<<endl;
cout << "minor:'"<<minor<<"'"<<endl;
Bag::bagit_version_major = stoi(major);
Bag::bagit_version_minor = stoi(minor);
stringstream utf8_ss (utf8_line);
string uprefix;
string uvalue;
getline(utf8_ss, uprefix, ' ');
getline(utf8_ss, uvalue, ' ');
if (0 != uprefix.compare("Tag-File-Character-Encoding:")) {
log << "wrong uprefix='" << uprefix << "', but 'Tag-File-Character-Encoding:' expected" << endl;
}
Bag::tag_file_character_encoding = uvalue;
cout << "Bagit Version ("<< version_line << ") major=" << Bag::bagit_version_major << " minor=" << Bag::bagit_version_minor << endl;
} else {
Bag::log << "file " << bagit_txt_path << " could not be opened" <<endl;
}
// read in payload
string payloaddir = dfname + "data/";
Bag::payload_p = new Payload( payloaddir ) ;
list<string> files = Bag::payload_p->get_all_relative_paths();
// read in payload manifest
Bag::payloadmanifest_p = new Payloadmanifest(dfname);
// read in tagmanifest
Bag::tagmanifest_p = new Tagmanifest(dfname);
list<string>::iterator i;
for (i=files.begin(); i!=files.end(); i++) {
cout << "file/dir (rel):" << (*i) << endl;
//cout << "file/dir (abs):" << (*i) << endl;
}
Bag::payloadmanifest_p->get_checksum_file_pairs( md5 );
Bag::tagmanifest_p->get_checksum_file_pairs( md5 );
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab