Giter Club home page Giter Club logo

bagittools's Introduction

BagItTools

Minimum PHP Version Github Actions LICENSE codecov

Introduction

BagItTools is a PHP implementation of the BagIt v1.0 specification (RFC-8493).

Features:

  • Create new bag
  • Load existing directory as a bag.
  • Load archive file (*.zip, *.tar, *.tar.gz, *.tgz, *.tar.bz2)
  • Validate a bag
  • Add/Remove files
  • Add/Remove fetch urls
  • Add/Remove hash algorithms (md5, sha1, sha224, sha256, sha384, sha512, sha3-224, sha3-256, sha3-384, sha3-512)
  • Generate payload for all data/ files for all hash algorithms (depending on PHP support)
  • Generate tag manifests for all root level files and any additional tag directories/files.
  • Add/Remove tags from bag-info.txt files, maintains ordering of tags loaded.
  • Generates/updates payload-oxum and bagging-date.
  • Passes all bagit-conformance-suite tests.
  • Create an archive (zip, tar, tar.gz, tgz, tar.bz2)
  • In-place upgrade of bag from v0.97 to v1.0

Installation

Composer

composer require "whikloj/bagittools"

Clone from Github

git clone https://github.com/whikloj/BagItTools
cd BagItTools
composer install --no-dev

Dependencies

All dependencies are installed or identified by composer.

Some PHP extensions are required and this library will not install if they cannot be found in the default PHP installation (the one used by composer).

The required extensions are:

Usage

You can integrate BagItTools into your own code as a library using the API, or use the CLI commands for some simple functionality.

Command line

Validating a bag

./bin/console validate <path to bag>

This will output a message as to whether the bag is or is NOT valid. It will also respond with an appropriate exit code (0 == valid, 1 == invalid).

If you add the -v flag it will also print any errors or warnings.

This can command can be used with the bagit-conformance-suite like this

./test-harness <path to BagItTools>/bin/console -- -v validate

API

API Documentation

Create a new bag

As this is a v1.0 implementation, by default bags created use the UTF-8 file encoding and the SHA-512 hash algorithm.

require_once './vendor/autoload.php';

use \whikloj\BagItTools\Bag;

$dir = "./newbag";

// Create new bag as directory $dir
$bag = Bag::create($dir);

// Add a file
$bag->addFile('../README.md', 'data/documentation/myreadme.md');

// Add another algorithm
$bag->addAlgorithm('sha1');

// Add a fetch url
$bag->addFetchFile('http://www.google.ca', 'data/mywebsite.html');

// Add some bag-info tags
$bag->addBagInfoTag('Contact-Name', 'Jared Whiklo');
$bag->addBagInfoTag('CONTACT-NAME', 'Additional admins');

// Check for tags.
if ($bag->hasBagInfoTag('contact-name')) {

    // Get tags
    $tags = $bag->getBagInfoByTag('contact-name');
    
    var_dump($tags); // array(
                     //    'Jared Whiklo',
                     //    'Additional admins',
                     // )

    // Remove a specific tag value using array index from the above listing.
    $bag->removeBagInfoTagIndex('contact-name', 1); 
    
    // Get tags
    $tags = $bag->getBagInfoByTag('contact-name');
    
    var_dump($tags); // array(
                     //    'Jared Whiklo',
                     // )

    // Remove all values for the specified tag.
    $bag->removeBagInfoTag('contact-name');
}

// Write bagit support files (manifests, bag-info, etc)
$bag->update();

// Write the bag to the specified path and filename using the expected archiving method.
$bag->package('./archive.tar.bz2');

Maintainer

Jared Whiklo

License

MIT

Development

To-Do:

  • CLI interface to handle simple bag CRUD (CReate/Update/Delete) functions.

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.