<commit_before>
# BagIt PHP

This is a PHP implementation of the [BagIt
0.96 specification](https://wiki.ucop.edu/display/Curation/BagIt)

## Supported Features:

* bag compiling
* manifest and tagmanifest generation
* generation of tag files, bag-info.txt and bagit.txt
* fetching remote files (fetch.txt)
* bag validation


## Installation

    % git clone git://github.com/scholarslab/BagItPHP.git

## Dependencies

You'll need to have these installed to use this:

 * Archive\_Tar (http://pear.php.net/package/Archive\_Tar)

## Example: Creating a bag
    
    require_once 'lib/bagit.php';
    
    define('BASE_DIR', 'testbag');

    // create a new bag at BASE_DIR
    $bag = new BagIt(BASE_DIR);

    // add a file; these are relative to the data directory
    $bag->addFile('../phpunit.xml', 'phpunit.xml');

    // create a tarball
    $bag->package('testbag');

## Example: Validating an existing bag

    require_once 'lib/bagit.php';

    // use an existing bag
    $bag = new BagIt('test/TestBag.tgz');

    // check validity
    var_dump((bool)$bag->isValid());

## Feedback

We are relying on the [GitHug issues tracker][issues] linked from the above for
feedback. File bugs or other issues [here][issues].

[issues]: http://github.com/scholarslab/BagItPHP/issues 

## Tests

The BagItPHP library includes unit tests to ensure the quality of the software.
The easiest way to contribute to the project is to contribute back to the project
with bugs and include a test case. Read the build.xml file more more information
on running tests, the underlying report types, and packing information.

<commit_msg>fixed typo; added another example<commit_after>
# BagIt PHP

This is a PHP implementation of the [BagIt
0.96 specification](https://wiki.ucop.edu/display/Curation/BagIt)

## Supported Features:

* bag compiling
* manifest and tagmanifest generation
* generation of tag files, bag-info.txt and bagit.txt
* fetching remote files (fetch.txt)
* bag validation


## Installation

    % git clone git://github.com/scholarslab/BagItPHP.git

## Dependencies

You'll need to have these installed to use this:

 * Archive\_Tar (http://pear.php.net/package/Archive\_Tar)

## Example: Creating a bag
    
    require_once 'lib/bagit.php';
    
    define('BASE_DIR', 'testbag');

    // create a new bag at BASE_DIR
    $bag = new BagIt(BASE_DIR);

    // add a file; these are relative to the data directory
    $bag->addFile('../phpunit.xml', 'phpunit.xml');

    // create a tarball
    $bag->package('testbag');

    // the bag package will be created at ./testbag.tgz

## Example: Validating an existing bag

    require_once 'lib/bagit.php';

    // use an existing bag
    $bag = new BagIt('test/TestBag.tgz');

    // check validity
    var_dump((bool)$bag->isValid());

## Example: Reading a bag

    require_once 'lib/bagit.php';

    // use an existing bag
    $bag = new BagIt('test/TestBag.tgz');

    // validate the bag
    $bag->validate();

    // only execute if a valid bag
    if(count($bag->getErrors()) == 0 {
      // retrieve remote files
      $bag->fetch->download();

      // copy files
      foreach($bag->getBagContents() as $filename) {
        copy($filename, 'final/destination/' . basename(filename));
      }
    }


## Feedback

We are relying on the [GitHub issues tracker][issues] linked from the above for
feedback. File bugs or other issues [here][issues].

[issues]: http://github.com/scholarslab/BagItPHP/issues 

## Tests

The BagItPHP library includes unit tests to ensure the quality of the software.
The easiest way to contribute to the project is to contribute back to the project
with bugs and include a test case. Read the build.xml file more more information
on running tests, the underlying report types, and packing information.


{'fraction_non_alphanumeric': 0.11160949868073879, 'fraction_numerical': 0.0018469656992084432, 'mean_word_length': 3.3325714285714287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6660619', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1102, 'n_words': 401}