ffi-libarchive 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.2 / 2011-04-12
2
+ * Writer::add_entry sets content size
3
+ * Modify usage of callbacks and FFI::Buffer to work with rubinius
4
+
1
5
  == 0.1.1 / 2011-04-11
2
6
  * Fix loading of library
3
7
 
File without changes
@@ -2,14 +2,6 @@ require 'ffi'
2
2
 
3
3
  module Archive
4
4
 
5
- module LibC
6
- extend FFI::Library
7
- ffi_lib FFI::Library::LIBC
8
-
9
- attach_variable :errno, :int
10
- attach_function :strerror, [:int], :string
11
- end
12
-
13
5
  module C
14
6
  def self.attach_function_maybe *args
15
7
  attach_function(*args)
@@ -43,7 +35,9 @@ module Archive
43
35
  callback :archive_open_callback, [:pointer, :pointer], :int
44
36
  callback :archive_write_callback, [:pointer, :pointer, :pointer, :size_t], :int
45
37
  callback :archive_close_callback, [:pointer, :pointer], :int
46
- attach_function :archive_write_open, [:pointer, :pointer, :archive_open_callback, :archive_write_callback, :archive_close_callback], :int
38
+ # TODO: the following function is the real definition but uses multiple callbacks. This implies that it will not work with Rubinius (currently), but luckily we only need the write-callback actually.
39
+ #attach_function :archive_write_open, [:pointer, :pointer, :archive_open_callback, :archive_write_callback, :archive_close_callback], :int
40
+ attach_function :archive_write_open, [:pointer, :pointer, :pointer, :archive_write_callback, :pointer], :int
47
41
  # TODO: catch errors if not defined
48
42
  attach_function :archive_write_set_compression_none, [:pointer], :int
49
43
  attach_function_maybe :archive_write_set_compression_gzip, [:pointer], :int
@@ -185,7 +185,7 @@ module Archive
185
185
  end
186
186
 
187
187
  stat = Archive::Stat::ffi_libarchive_create_lstat(filename)
188
- raise Error, "Copy stat failed: #{LibC::strerror(LibC::errno)}" if stat.null?
188
+ raise Error, "Copy stat failed: #{Archive::Stat::ffi_error}" if stat.null?
189
189
  result = C::archive_entry_copy_stat(entry, stat)
190
190
  ensure
191
191
  Archive::Stat::ffi_libarchive_free_stat(stat)
@@ -210,7 +210,7 @@ module Archive
210
210
  end
211
211
 
212
212
  stat = Archive::Stat::ffi_libarchive_create_stat(filename)
213
- raise Error, "Copy stat failed: #{LibC::strerror(LibC::errno)}" if stat.null?
213
+ raise Error, "Copy stat failed: #{Archive::Stat::ffi_error}" if stat.null?
214
214
  result = C::archive_entry_copy_stat(entry, stat)
215
215
  ensure
216
216
  Archive::Stat::ffi_libarchive_free_stat(stat)
@@ -46,9 +46,9 @@ module Archive
46
46
  raise Error, @archive if C::archive_read_open_filename(archive, params[:file_name], 1024) != C::OK
47
47
  elsif params[:memory]
48
48
  str = params[:memory]
49
- @data = FFI::MemoryPointer.new str.size
50
- @data.put_bytes 0, str
51
- raise Error, @archive if C::archive_read_open_memory(archive, @data, @data.size) != C::OK
49
+ @data = FFI::MemoryPointer.new(str.size + 1)
50
+ @data.write_string str, str.size
51
+ raise Error, @archive if C::archive_read_open_memory(archive, @data, str.size) != C::OK
52
52
  end
53
53
  rescue
54
54
  close
@@ -101,7 +101,7 @@ module Archive
101
101
  block = data.method :concat
102
102
  end
103
103
 
104
- buffer = FFI::Buffer.alloc_out(size)
104
+ buffer = FFI::MemoryPointer.new(size)
105
105
  len = 0
106
106
  while (n = C::archive_read_data(archive, buffer, size)) > 0
107
107
  case n
@@ -7,6 +7,8 @@ module Archive
7
7
  builder.include 'stdlib.h'
8
8
  builder.include 'sys/types.h'
9
9
  builder.include 'sys/stat.h'
10
+ builder.include 'string.h'
11
+ builder.include 'errno.h'
10
12
  builder.c %q{
11
13
  void* ffi_libarchive_create_stat(const char* filename) {
12
14
  struct stat* s = malloc(sizeof(struct stat));
@@ -26,6 +28,11 @@ module Archive
26
28
  free((struct stat*)s);
27
29
  }
28
30
  }
31
+ builder.c %q{
32
+ const char* ffi_error() {
33
+ return strerror(errno);
34
+ }
35
+ }
29
36
  end
30
37
  end
31
38
  end
@@ -58,9 +58,12 @@ module Archive
58
58
  if params[:file_name]
59
59
  raise Error, @archive if C::archive_write_open_filename(archive, params[:file_name]) != C::OK
60
60
  elsif params[:memory]
61
+ if C::archive_write_get_bytes_in_last_block(@archive) == -1
62
+ C::archive_write_set_bytes_in_last_block(archive, 1)
63
+ end
61
64
  @data = write_callback params[:memory]
62
65
  raise Error, @archive if C::archive_write_open(archive, nil,
63
- method(:open_callback),
66
+ nil,
64
67
  @data,
65
68
  nil) != C::OK
66
69
  end
@@ -69,14 +72,6 @@ module Archive
69
72
  raise
70
73
  end
71
74
 
72
- def open_callback archive, client
73
- if C::archive_write_get_bytes_in_last_block(archive) == -1
74
- C::archive_write_set_bytes_in_last_block(archive, 1)
75
- end
76
- C::OK
77
- end
78
- private :open_callback
79
-
80
75
  def write_callback data
81
76
  Proc.new { |ar, client, buffer, length|
82
77
  data.concat buffer.get_bytes(0,length)
@@ -104,8 +99,14 @@ module Archive
104
99
 
105
100
  entry = Entry.new
106
101
  data = yield entry
107
- write_header entry
108
- write_data data if data
102
+ if data
103
+ entry.size = data.size
104
+ write_header entry
105
+ write_data data
106
+ else
107
+ write_header entry
108
+ end
109
+ nil
109
110
  ensure
110
111
  entry.close
111
112
  end
data/version.txt CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ffi-libarchive
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Frank Fischer
@@ -10,8 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-11 00:00:00 +02:00
14
- default_executable:
13
+ date: 2011-04-12 00:00:00 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: ffi
@@ -45,7 +44,6 @@ extra_rdoc_files:
45
44
  - History.txt
46
45
  - bin/ffi-libarchive-ruby
47
46
  files:
48
- - .bnsignore
49
47
  - History.txt
50
48
  - README.md
51
49
  - Rakefile
@@ -56,13 +54,11 @@ files:
56
54
  - lib/ffi-libarchive/reader.rb
57
55
  - lib/ffi-libarchive/stat.rb
58
56
  - lib/ffi-libarchive/writer.rb
59
- - test.tgz
60
57
  - test/data/test.tar.gz
61
58
  - test/sets/ts_read.rb
62
59
  - test/sets/ts_write.rb
63
60
  - test/test_ffi-libarchive.rb
64
61
  - version.txt
65
- has_rdoc: true
66
62
  homepage: http://darcsden.com/lyro/ffi-libarchive
67
63
  licenses: []
68
64
 
@@ -87,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
83
  requirements: []
88
84
 
89
85
  rubyforge_project: ffi-libarchive
90
- rubygems_version: 1.6.2
86
+ rubygems_version: 1.7.2
91
87
  signing_key:
92
88
  specification_version: 3
93
89
  summary: An ffi binding to libarchive.
data/.bnsignore DELETED
@@ -1,20 +0,0 @@
1
- # The list of files that should be ignored by Mr Bones.
2
- # Lines that start with '#' are comments.
3
- #
4
- # A .gitignore file can be used instead by setting it as the ignore
5
- # file in your Rakefile:
6
- #
7
- # Bones {
8
- # ignore_file '.gitignore'
9
- # }
10
- #
11
- # For a project with a C extension, the following would be a good set of
12
- # exclude patterns (uncomment them if you want to use them):
13
- # *.[oa]
14
- # *~
15
- _darcs
16
- announcement.txt
17
- coverage
18
- doc
19
- pkg
20
- *.rbc
data/test.tgz DELETED
Binary file