The BAGIT LIBRARY is a software library intended to support the creation, manipulation, and validation of bags. Its current version is 0.97. It is version aware with the earliest supported version being 0.93.
- Java 8
- gradle (for development only)
- The Digital Curation Google Group (https://groups.google.com/d/forum/digital-curation) is an open discussion list that reaches many of the contributors to and users of this open-source project
- If you have found a bug please create a new issue on the issues page
- To contact a developer at the Library of Congress please email repo-dev@listserv.loc.gov
- If you would like to contribute, please submit a pull request
The 5.x versions do not include a command-line interface. Users who need a command-line utility can continue to use the latest 4.x release (download 4.12.1 or switch to an alternative implementation such as bagit-python or BagIt for Ruby.
Starting with the 5.x versions bagit-java no longer supports directly serializing a bag to an archive file. The examples show how to implement a custom serializer for the zip and tar formats.
The 5.x versions do not include a core fetch.txt
implementation. If you need
this functionality, the
FetchHttpFileExample
example
demonstrates how you can implement this feature with your additional application
and workflow requirements.
The 5.x version is a complete rewrite of the bagit-java library which attempts to follow modern Java practices and will require some changes to existing code:
Path folder = Paths.get("FolderYouWantToBag");
StandardSupportedAlgorithms algorithm = StandardSupportedAlgorithms.MD5;
boolean includeHiddenFiles = false;
Bag bag = BagCreator.bagInPlace(folder, algorithm, includeHiddenFiles);
Path rootDir = Paths.get("RootDirectoryOfExistingBag");
BagReader reader = new BagReader();
Bag bag = reader.read(rootDir);
Path outputDir = Paths.get("WhereYouWantToWriteTheBagTo");
BagWriter.write(bag, outputDir); //where bag is a Bag object
boolean ignoreHiddenFiles = true;
BagVerifier verifier = new BagVerifier();
verifier.isComplete(bag, ignoreHiddenFiles);
boolean ignoreHiddenFiles = true;
BagVerifier verifier = new BagVerifier();
verifier.isValid(bag, ignoreHiddenFiles);
boolean ignoreHiddenFiles = true;
BagVerifier verifier = new BagVerifier();
if(verifier.canQuickVerify(bag)){
verifier.quicklyVerify(bag, ignoreHiddenFiles);
}
You only need to implement 2 interfaces:
public class MyNewSupportedAlgorithm implements SupportedAlgorithm {
@Override
public String getMessageDigestName() {
return "SHA3-256";
}
@Override
public String getBagitName() {
return "sha3256";
}
}
public class MyNewNameMapping implements BagitAlgorithmNameToSupportedAlgorithmMapping {
@Override
public SupportedAlgorithm getMessageDigestName(String bagitAlgorithmName) {
if("sha3256".equals(bagitAlgorithmName)){
return new MyNewSupportedAlgorithm();
}
return StandardSupportedAlgorithms.valueOf(bagitAlgorithmName.toUpperCase());
}
}
and then add the implemented BagitAlgorithmNameToSupportedAlgorithmMapping
class to your BagReader
or bagVerifier
object before using their methods.
The BagIt format is extremely flexible and allows for some conditions which are
technically allowed but should be avoided to minimize confusion and maximize
portability. The BagLinter
class allows you to easily check a bag for
warnings:
Path rootDir = Paths.get("RootDirectoryOfExistingBag");
BagLinter linter = new BagLinter();
List<BagitWarning> warnings = linter.lintBag(rootDir, Collections.emptyList());
You can provide a list of specific warnings to ignore:
dependencycheckth rootDir = Paths.get("RootDirectoryOfExistingBag");
BagLinter linter = new BagLinter();
List<BagitWarning> warnings = linter.lintBag(rootDir, Arrays.asList(BagitWarning.OLD_BAGIT_VERSION);
Bagit-Java uses Gradle for its build system. Check out the great documentation to learn more.
Inside the bagit-java root directory, run gradle check
.
- Follow their guides
- http://central.sonatype.org/pages/releasing-the-deployment.html
- https://issues.sonatype.org/secure/Dashboard.jspa
- Once you have access, to create an office release and upload it you should specify the version by running
gradle -Pversion=<VERSION> uploadArchives
- Don't forget to tag the repository!
Simply run gradle eclipse
and it will automatically create a eclipse project for you that you can import.
- Further refine reading and writing of bags version 0.93-0.97
- Fix bugs/issues reported with new library (on going)