Giter VIP home page Giter VIP logo

bagit_sharp's Introduction

bagit_sharp

bagit-sharp is a C# library for working with [BagIt] (http://purl.org/net/bagit) style packages. It's functionality loosely tries to emulate the functionality found in the [bagit-python] (https://github.com/LibraryOfCongress/bagit-python) project

Dependencies

No.

Installation

The project includes a Visual Studio project file. To build a binary library from the code you will need to:

  1. Open the project in [Visual Studio] (https://www.visualstudio.com/downloads/) or compatible tool
  2. Build

To simplify use, there is also a binary copy available via Release that includes binaries of both the bagit-sharp library and the referenced SharpZipLib code that it's built against.

Usage

The Library provides an object representation of a bag. This includes properties, etc. To create a new bag:

bagit_sharp.Bag objB = new bagit_sharp.Bag();
//Create an event handler to handle updates 
//from the library
objB.UpdateStatus += ObjB_UpdateStatus;

objB.add_to_header("Contact-Name", "Your Contact Name");
objB.add_to_header("Organization-Address", "Your Address);
objB.add_to_header("Contact-Email", "your_email");
bagit_sharp.Bag.CHECKSUM_ALGOS checksum = bagit_sharp.Bag.CHECKSUM_ALGOS.md5;

string[] objects_to_bag = new string[2] {@"D:\folder1\", @"D:\folder2\"};
bagit_sharp.Bag mybag = objB.Make_Bag(objects_to_bag, @"D:\Bags\new_bag\", null, 1, checksum);
if (mybag != null) {
   MessageBox.Show("Bag Created");
} else {
   MessageBox.Show("Bag not created: " + objB.ErrorMessage);
}

If you wish to load a bag to zip or to validate

bagit_sharp.Bag objB = new bagit_sharp.Bag(@"D:\Bags\new_bag\");

To Validate

bagit_sharp.Bag objB = new bagit_sharp.Bag(@"D:\Bags\new_bag\");

try {
  objB.Validate_Bag();
  MessageBox.Show("Valid!");
} catch (bagit_sharp.BagException ex)
{
  if (String.IsNullOrEmpty(objB.Payload_Oxum()))
  {
      try {
         //don't try to fast validate because
         //no oxum was present
         objB.Validate_Bag(null, false);
         MessageBox.Show("Valid!");
      } catch (bagit_sharp.BagException bex) {
         MessageBox.Show(bex.Message);
      }
  } else {
      MessageBox.Show(ex.Message);
  }
}

To Zip:

bagit_sharp.Bag objB = new bagit_sharp.Bag(@"D:\Bags\new_bag\");
if (objB.ZipFile() == false) {
  MessageBox.Show("Zip not successful");
} else {
  MessageBox.Show("Bag was Zipped");
}

When zipping a file, the zip file is created at the same level as the top bag folder. With the zip file, a checksum file will also be created, utilizing MD5 as the default.

Supported Checksums

The bagit_sharp library supports the following common checksums

  1. MD5
  2. SH1
  3. SH256
  4. SH384
  5. SH512

Update a bag manifest:

//Assuming new files have been added to the data
//directory, or you have used a function to 
//modify the bag_info
try {
   bagit_sharp.Bag objBag = new bagit_sharp.Bag("D:\mybag");
   if (objBag.Update_Manifest() == null) {
      MessageBox.Show("Unable to update your bag");
   } else {
      MessageBox.Show("Bag has been updated.");
   }
} catch {
    MessageBox.Show("An Unhandled Error occurred during the process");
}

Contributing to the bagit_sharp development

I invite anyone that is interested to clone the project, make changes, and submit the changes back to project.

Testing

ToDo

License:

MIT License

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.