Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeymorozov committed Feb 11, 2021
0 parents commit 938b083
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.bundle
*.so
*.o
*.a
mkmf.log
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"

# Specify your gem's dependencies in xarb.gemspec
gemspec
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions lib/xar.rb
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions lib/xar/archive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Xar::Archive
def initialize(xar_t)
@xar_t = xar_t
end
end
59 changes: 59 additions & 0 deletions lib/xar/native.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions xar.gemspec
Original file line number Diff line number Diff line change
@@ -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 = ["[email protected]"]
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

0 comments on commit 938b083

Please sign in to comment.