diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3fdc2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +/.bundle/ +/.yardoc +/Gemfile.lock +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ +*.bundle +*.so +*.o +*.a +mkmf.log diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..0e056c9 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "https://rubygems.org" + +# Specify your gem's dependencies in xarb.gemspec +gemspec diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..b21fa81 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,22 @@ +Copyright (c) 2014 Adam Tanner + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e746716 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# Xar + +Xar provides Ruby FFI bindings to libxar. + +## Installation + +Add this line to your application's Gemfile: + +```ruby +gem "xar" +``` + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install xar + +## Usage + +TODO: Write usage instructions here + +## Contributing + +1. Fork it ( https://github.com/[my-github-username]/xar/fork ) +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create a new Pull Request diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..8aafd34 --- /dev/null +++ b/Rakefile @@ -0,0 +1,8 @@ +require "bundler/gem_tasks" +require "rake/testtask" + +Rake::TestTask.new do |t| + t.pattern = "spec/**/*_spec.rb" +end + +task default: :test diff --git a/lib/xar.rb b/lib/xar.rb new file mode 100644 index 0000000..fa2817e --- /dev/null +++ b/lib/xar.rb @@ -0,0 +1,13 @@ +require "ffi" +require "ffi/stat" + +module Xar + def self.open(path, flag) + xar_t = Xar::Native.xar_open(path, flag) + + Xar::Archive.new(xar_t) + end +end + +require "xar/native" +require "xar/archive" diff --git a/lib/xar/archive.rb b/lib/xar/archive.rb new file mode 100644 index 0000000..24f6382 --- /dev/null +++ b/lib/xar/archive.rb @@ -0,0 +1,5 @@ +class Xar::Archive + def initialize(xar_t) + @xar_t = xar_t + end +end diff --git a/lib/xar/native.rb b/lib/xar/native.rb new file mode 100644 index 0000000..33bbbac --- /dev/null +++ b/lib/xar/native.rb @@ -0,0 +1,59 @@ +module Xar::Native + extend FFI::Library + + ffi_lib "libxar" + + typedef :pointer, :xar_t + typedef :pointer, :xar_file_t + typedef :pointer, :xar_iter_t + typedef :pointer, :xar_subdoc_t + typedef :pointer, :xar_errctx_t + + callback :err_handler_callback, [:int32, :int32, :xar_errctx_t, :pointer], :int32 + + FLAG = enum :read, 0, + :write, 1 + + attach_function :xar_open, [:string, FLAG], :xar_t + attach_function :xar_close, [:xar_t], :void + + attach_function :xar_add, [:xar_t, :string], :xar_file_t + attach_function :xar_add_frombuffer, [:xar_t, :xar_file_t, :string, :string, :size_t], :xar_file_t + attach_function :xar_add_folder, [:xar_t, :xar_file_t, :string, FFI::Stat::Stat], :xar_file_t + + attach_function :xar_extract, [:xar_t, :xar_file_t], :int32 + + attach_function :xar_register_errhandler, [:xar_t, :err_handler_callback, :pointer], :void + attach_function :xar_err_get_file, [:xar_errctx_t], :xar_file_t + attach_function :xar_err_get_string, [:xar_errctx_t], :string + attach_function :xar_err_get_errno, [:xar_errctx_t], :int + + attach_function :xar_iter_new, [:void], :xar_iter_t + attach_function :xar_iter_free, [:xar_iter_t], :void + + attach_function :xar_file_first, [:xar_t, :xar_iter_t], :xar_file_t + attach_function :xar_file_next, [:xar_iter_t], :xar_file_t + + attach_function :xar_opt_set, [:xar_t, :string, :string], :int32 + attach_function :xar_opt_get, [:xar_t, :string], :string + + attach_function :xar_prop_set, [:xar_file_t, :string, :string], :int32 + attach_function :xar_prop_get, [:xar_file_t, :string, :pointer], :int32 + attach_function :xar_prop_first, [:xar_file_t, :xar_iter_t], :string + attach_function :xar_prop_next, [:xar_iter_t], :string + + attach_function :xar_attr_set, [:xar_file_t, :string, :string, :string], :int32 + attach_function :xar_attr_get, [:xar_file_t, :string, :string], :string + attach_function :xar_attr_first, [:xar_file_t, :string, :xar_iter_t], :string + attach_function :xar_attr_next, [:xar_iter_t], :string + + attach_function :xar_subdoc_new, [:xar_t, :string], :xar_subdoc_t + attach_function :xar_subdoc_prop_set, [:xar_subdoc_t, :string, :string], :int32 + attach_function :xar_subdoc_prop_get, [:xar_subdoc_t, :string, :pointer], :int32 + attach_function :xar_subdoc_first, [:xar_t], :xar_subdoc_t + attach_function :xar_subdoc_next, [:xar_subdoc_t], :xar_subdoc_t + attach_function :xar_subdoc_name, [:xar_subdoc_t], :string + attach_function :xar_subdoc_copyout, [:xar_subdoc_t, :pointer, :pointer], :int32 + attach_function :xar_subdoc_copyin, [:xar_subdoc_t, :string, :int], :int32 + attach_function :xar_subdoc_remove, [:xar_subdoc_t], :void +end diff --git a/xar.gemspec b/xar.gemspec new file mode 100644 index 0000000..e59fba9 --- /dev/null +++ b/xar.gemspec @@ -0,0 +1,24 @@ +# coding: utf-8 +lib = File.expand_path("../lib", __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) + +Gem::Specification.new do |spec| + spec.name = "xar" + spec.version = "0.0.0" + spec.authors = ["Adam Tanner"] + spec.email = ["adam@adamtanner.org"] + spec.summary = %q{ Ruby FFI bindings to libxar. } + spec.description = %q{ Ruby FFI bindings to libxar. } + spec.homepage = "https://github.com/adamtanner/xar" + spec.license = "MIT" + + spec.files = `git ls-files -z`.split("\x0") + spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) } + spec.test_files = spec.files.grep(%r{^spec/}) + spec.require_paths = ["lib"] + + spec.add_dependency "ffi" + spec.add_dependency "ffi-stat" + spec.add_development_dependency "bundler", "~> 1.7" + spec.add_development_dependency "rake", "~> 10.0" +end