Hydra file characterization (extracted from Sufia)
Clone or download
little9 Merge pull request #37 from samvera/1.0.0
Release version 1.0.0
Latest commit 73aa000 Aug 21, 2018



Code: Version Build Status Coverage Status

Docs: Contribution Guidelines Apache 2.0 License

Jump in: Slack Status

What is hydra-file_characterization?

Provides a wrapper for file characterization.

Product Owner & Maintenance

hydra-file_characterization is a Core Component of the Samvera community. The documentation for what this means can be found here.

Product Owner



The Samvera community is here to help. Please see our support guide.

Getting Started

If you are using Rails add the following to an initializer (./config/initializers/hydra-file_characterization_config.rb):

Hydra::FileCharacterization.configure do |config|
  config.tool_path(:fits, '/path/to/fits')
Hydra::FileCharacterization.characterize(File.read(filename), File.basename(filename), :fits)```

* Why `file.read`? To highlight that we want a string. In the case of ActiveFedora, we have a StringIO instead of a file.
* Why `file.basename`? In the case of Fits, the characterization takes cues from the extension name.

You can call a single characterizer…

xml_string = Hydra::FileCharacterization.characterize(File.read("/path/to/my/file.rb"), 'file.rb', :fits)

…for this particular call, you can specify custom fits path…

xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.rb', :fits) do |config|
  config[:fits] = './really/custom/path/to/fits'

…or even make the path callable…

xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.rb', :fits) do |config|
  config[:fits] = lambda {|filename| … }

…or even create your custom characterizer on the file…

xml_string = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.rb', :my_characterizer) do |config|
  config[:my_characterizer] = lambda {|filename| … }

You can also call multiple characterizers at the same time.

fits_xml, ffprobe_xml = Hydra::FileCharacterization.characterize(contents_of_a_file, 'file.rb', :fits, :ffprobe)

Registering New Characterizers

This is possible by adding a characterizer to the Hydra::FileCharacterization::Characterizers' namespace.


This software has been developed by and is brought to you by the Samvera community. Learn more at the Samvera website.

Samvera Logo