bzip2-ruby-rb20 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d53fed8813747479d6f28b31d519c2e160266f73
4
+ data.tar.gz: d35d85059cfd805ca21b56c13f8f0d8c98a6647d
5
+ SHA512:
6
+ metadata.gz: 9f932725f330c2524e9639ca0f808902035e392e6f9471212b235dd6f0cdaff53d70b388464e8b4c02c564b1c65b0de9af594341e53c7c77995bda893ee1797f
7
+ data.tar.gz: 7969c3049e2e1fbff585adddf83ac952157a903ac93ee294e7cc00ce26d5219b977d3d8174d1bba13e09f08e8f62446d5b43336793fca86e8356869e59f9ef9f
@@ -0,0 +1,10 @@
1
+ _10lines_
2
+ doc
3
+ ext/Makefile
4
+ *.o
5
+ *.so
6
+ *.bundle
7
+ pkg
8
+ .bundle
9
+ tmp
10
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format=documentation
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - rbx
7
+ - ree
8
+ - ruby-head
9
+ - rbx-18mode
10
+ - rbx-19mode
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: rbx-18mode
14
+ - rvm: rbx-19mode
15
+ script:
16
+ - bundle exec rake
17
+ - bundle exec rspec
@@ -0,0 +1 @@
1
+ --no-private
@@ -0,0 +1,94 @@
1
+ ## 0.2.7 2010-11-16
2
+
3
+ * Add documentation for an overview of the Bzip2 module
4
+ * Document the class methods on Bzip2 and get them to show up in yarddoc
5
+ * Remove the ConfigError class because searching for it showed no instances of its usage
6
+ * Add a Usage section to the README and a bit about adding it to a Gemfile
7
+ * Improve the reader_spec.rb by making it more resilient in lots of places and a bit more descriptive/terse in
8
+ * Add a lot more documentation for the Reader class and also touch up the Writer class a bit
9
+ * Make the Writer specs more descriptive by giving them some doc strings.
10
+ * Wrap up documentation of the Bzip2::Writer class.
11
+ * Add lib/bzip2-ruby.rb so it's not always necessary to specify to require 'bzip2' in Gemfiles and such
12
+ * Start documenting the Bzip2::Writer class
13
+ * Fix a few compiler warnings
14
+ * Removed some dead code
15
+ * Fix for ruby 1.9 compatibility.
16
+ * Fix segfault when exiting in ruby 1.9
17
+ * Follow the newer conventions of rspec
18
+ * Migrate to using Bundler instead of Jeweler
19
+ * use malloc/free instead of ruby_xmalloc/ruby_xfree
20
+
21
+ ## 0.2.6 2009-10-6
22
+
23
+ * Updated to support Ruby 1.8.5
24
+
25
+ ## 0.2.5 2009-06-07
26
+
27
+ * initial conversion of original tests over to rspec
28
+
29
+ ## 0.2.4 2009-05-02
30
+
31
+ * renamed BZ2 module/namespace to Bzip2
32
+
33
+ ## 0.2.3 2009-05-02
34
+
35
+ * renamed gem to bzip2-ruby from bz2
36
+ * initial conversion to jeweler
37
+ * bundling gemspec
38
+ * README and file structure organization updates
39
+ * updated Init_*() ruby initializer function to match new gem name
40
+
41
+ ## 0.2.2 2008-12-22
42
+
43
+ * 1 major enhancement:
44
+ * Gemify bz2 library from http://moulon.inra.fr/ruby/bz2.html
45
+ * All credit goes to Guy Decoux <ts@moulon.inra.fr>
46
+
47
+ ## 0.2.1
48
+
49
+ * replaced rb_proc_new() with bz_proc_new() for 1.6
50
+ (Thanks "Akinori MUSHA" <knu@iDaemons.org>)
51
+
52
+ ## 0.1.9
53
+
54
+ * corrected BZ_FINISH_OK (Thanks Rudi Cilibrasi <Rudi.Cilibrasi@cwi.nl>)
55
+
56
+ ## 0.1.6
57
+
58
+ * adapted for 1.8.0 (ihi)
59
+ * modified ::new
60
+ * BZ2::Writer#finish (same than #flush)
61
+
62
+ ## 0.1.5
63
+
64
+ * corrected extconf.rb
65
+ * added close!
66
+ * replaced close(false) by #finish
67
+ * corrected #flush
68
+
69
+ ## 0.1.4
70
+
71
+ * corrected bz_iv
72
+ * #to_io
73
+ * corrected ::Reader#close
74
+
75
+ ## 0.1.3
76
+
77
+ * corrected #lineno
78
+ * corrected ::Writer::new(nil)
79
+ * taint result
80
+
81
+ ## 0.1.2
82
+
83
+ * better (???) interface for #read
84
+ * finalize for objects which respond to #closed?
85
+
86
+ ## 0.1.1
87
+
88
+ * better interface for T_FILE
89
+ * corrected bug with gc (buf)
90
+ * Reader#lineno, Reader#lineno=, Reader#ungets
91
+ * corrected Reader#unused
92
+ * taint check in #initialize
93
+ * BZ2::bzip2, BZ2::bunzip2
94
+ * too many exceptions
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,69 @@
1
+ # Ruby C bindings to libbzip2
2
+
3
+ ## Installation
4
+
5
+ First make sure you’ve got Gemcutter in your sources list:
6
+
7
+ `gem sources -a http://gemcutter.org`
8
+
9
+ Then go ahead and install it as usual:
10
+
11
+ `sudo gem install bzip2-ruby`
12
+
13
+ You may need to specify:
14
+
15
+ `--with-bz2-dir=<include file directory for libbzip2>`
16
+
17
+ Or in a Gemfile
18
+
19
+ `gem 'bzip2-ruby'`
20
+
21
+ ## Usage
22
+
23
+ The full documentation is hosted on [rdoc.info](http://rdoc.info/github/brianmario/bzip2-ruby/master/frames).
24
+
25
+ Here's a quick overview, hower:
26
+
27
+ ``` ruby
28
+ require 'bzip2'
29
+
30
+ # Quick shortcuts
31
+ data = Bzip2.compress 'string'
32
+ Bzip2.uncompress data
33
+
34
+ # Creating a bz2 compressed file
35
+ writer = Bzip2::Writer.new File.open('file')
36
+ writer << 'data1'
37
+ writer.puts 'data2'
38
+ writer.print 'data3'
39
+ writer.printf '%s', 'data4'
40
+ writer.close
41
+
42
+ Bzip2::Writer.open('file'){ |f| f << data }
43
+
44
+ # Reading a bz2 compressed file
45
+ reader = Bzip2::Reader.new File.open('file')
46
+ reader.gets # => "data1data2\n"
47
+ reader.read # => 'data3data4'
48
+
49
+ reader.readline # => raises Bzip2::EOZError
50
+
51
+ Bzip2::Reader.open('file'){ |f| puts f.read }
52
+ ```
53
+
54
+ ## Copying
55
+
56
+ ```
57
+ This extension module is copyrighted free software by Guy Decoux
58
+ You can redistribute it and/or modify it under the same term as Ruby.
59
+ Guy Decoux <ts@moulon.inra.fr>
60
+ ```
61
+
62
+ ## Modifications from origin version
63
+
64
+ * Switch to Jeweler
65
+ * Renamed BZ2 module/namespace to Bzip2
66
+ * Renamed compiled binary from "bz2" to "bzip2"
67
+ * Renamed gem from "bz2" to "bzip2-ruby"
68
+ * Converted original tests to rspec
69
+ * 1.9 compatibility
@@ -0,0 +1,35 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ # rspec
5
+ begin
6
+ require 'rspec'
7
+ require 'rspec/core/rake_task'
8
+
9
+ desc "Run all examples with RCov"
10
+ RSpec::Core::RakeTask.new('spec:rcov') do |t|
11
+ t.rcov = true
12
+ end
13
+ RSpec::Core::RakeTask.new('spec') do |t|
14
+ t.verbose = true
15
+ end
16
+
17
+ task :default => :spec
18
+ rescue LoadError
19
+ puts "rspec, or one of its dependencies, is not available. Install it with: sudo gem install rspec"
20
+ end
21
+
22
+ # rake-compiler
23
+ require 'rake' unless defined? Rake
24
+
25
+ gem 'rake-compiler', '>= 0.7.5'
26
+ require "rake/extensiontask"
27
+
28
+ Rake::ExtensionTask.new('bzip2') do |ext|
29
+ ext.cross_compile = true
30
+ ext.cross_platform = ['x86-mingw32', 'x86-mswin32-60']
31
+
32
+ ext.lib_dir = File.join 'lib', 'bzip2'
33
+ end
34
+
35
+ Rake::Task[:spec].prerequisites << :compile
@@ -0,0 +1,21 @@
1
+ require './lib/bzip2/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'bzip2-ruby-rb20'
5
+ s.version = Bzip2::VERSION
6
+ s.authors = ['Guy Decoux', 'Brian Lopezs']
7
+ s.date = Time.now.utc.strftime("%Y-%m-%d")
8
+ s.email = ['seniorlopez@gmail.com']
9
+ s.extensions = ['ext/bzip2/extconf.rb']
10
+ s.files = `git ls-files`.split("\n")
11
+ s.homepage = 'http://github.com/brianmario/bzip2-ruby'
12
+ s.rdoc_options = ["--charset=UTF-8"]
13
+ s.require_paths = ['lib']
14
+ s.rubygems_version = %q{1.4.2}
15
+ s.summary = 'Ruby C bindings to libbzip2.'
16
+ s.test_files = `git ls-files spec`.split("\n")
17
+
18
+ # tests
19
+ s.add_development_dependency 'rake-compiler', ">= 0.7.5"
20
+ s.add_development_dependency 'rspec', ">= 2.0.0"
21
+ end
@@ -0,0 +1,250 @@
1
+ #include <ruby.h>
2
+ #include <bzlib.h>
3
+
4
+ #include "common.h"
5
+ #include "reader.h"
6
+ #include "writer.h"
7
+
8
+ VALUE bz_cWriter, bz_cReader, bz_cInternal;
9
+ VALUE bz_eError, bz_eEOZError;
10
+
11
+ VALUE bz_internal_ary;
12
+
13
+ ID id_new, id_write, id_open, id_flush, id_read;
14
+ ID id_closed, id_close, id_str;
15
+
16
+ void bz_internal_finalize(VALUE data) {
17
+ VALUE elem;
18
+ int closed, i;
19
+ struct bz_iv *bziv;
20
+ struct bz_file *bzf;
21
+
22
+ for (i = 0; i < RARRAY_LEN(bz_internal_ary); i++) {
23
+ elem = RARRAY_PTR(bz_internal_ary)[i];
24
+ Data_Get_Struct(elem, struct bz_iv, bziv);
25
+ if (bziv->bz2) {
26
+ RDATA(bziv->bz2)->dfree = free;
27
+ if (TYPE(bziv->io) == T_FILE) {
28
+ RFILE(bziv->io)->fptr->finalize = bziv->finalize;
29
+ } else if (TYPE(bziv->io) == T_DATA) {
30
+ RDATA(bziv->io)->dfree = bziv->finalize;
31
+ }
32
+ Data_Get_Struct(bziv->bz2, struct bz_file, bzf);
33
+ closed = bz_writer_internal_flush(bzf);
34
+ if (bzf->flags & BZ2_RB_CLOSE) {
35
+ bzf->flags &= ~BZ2_RB_CLOSE;
36
+ if (!closed && rb_respond_to(bzf->io, id_close)) {
37
+ rb_funcall2(bzf->io, id_close, 0, 0);
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
43
+
44
+ /*
45
+ * call-seq:
46
+ * compress(str)
47
+ *
48
+ * Shortcut for compressing just a string.
49
+ *
50
+ * Bzip2.uncompress Bzip2.compress('data') # => 'data'
51
+ *
52
+ * @param [String] str the string to compress
53
+ * @return [String] +str+ compressed with bz2
54
+ */
55
+ VALUE bz_compress(VALUE self, VALUE str) {
56
+ VALUE bz2, argv[1] = {Qnil};
57
+
58
+ str = rb_str_to_str(str);
59
+ bz2 = rb_funcall2(bz_cWriter, id_new, 1, argv);
60
+ if (OBJ_TAINTED(str)) {
61
+ struct bz_file *bzf;
62
+ Data_Get_Struct(bz2, struct bz_file, bzf);
63
+ OBJ_TAINT(bzf->io);
64
+ }
65
+ bz_writer_write(bz2, str);
66
+ return bz_writer_close(bz2);
67
+ }
68
+
69
+ /*
70
+ * Returns the io stream underlying this stream. If the strem was constructed
71
+ * with a file, that is returned. Otherwise, an empty string is returned.
72
+ *
73
+ * @return [File, String] similar to whatever the stream was constructed with
74
+ * @raise [IOError] if the stream has been closed
75
+ */
76
+ VALUE bz_to_io(VALUE obj) {
77
+ struct bz_file *bzf;
78
+
79
+ Get_BZ2(obj, bzf);
80
+ return bzf->io;
81
+ }
82
+
83
+ VALUE bz_str_read(int argc, VALUE *argv, VALUE obj) {
84
+ struct bz_str *bzs;
85
+ VALUE res, len;
86
+ int count;
87
+
88
+ Data_Get_Struct(obj, struct bz_str, bzs);
89
+ rb_scan_args(argc, argv, "01", &len);
90
+ if (NIL_P(len)) {
91
+ count = (int) RSTRING_LEN(bzs->str);
92
+ } else {
93
+ count = NUM2INT(len);
94
+ if (count < 0) {
95
+ rb_raise(rb_eArgError, "negative length %d given", count);
96
+ }
97
+ }
98
+ if (!count || bzs->pos == -1) {
99
+ return Qnil;
100
+ }
101
+ if ((bzs->pos + count) >= RSTRING_LEN(bzs->str)) {
102
+ res = rb_str_new(RSTRING_PTR(bzs->str) + bzs->pos,
103
+ RSTRING_LEN(bzs->str) - bzs->pos);
104
+ bzs->pos = -1;
105
+ } else {
106
+ res = rb_str_new(RSTRING_PTR(bzs->str) + bzs->pos, count);
107
+ bzs->pos += count;
108
+ }
109
+ return res;
110
+ }
111
+
112
+ /*
113
+ * call-seq:
114
+ * uncompress(data)
115
+ * Decompress a string of bz2 compressed data.
116
+ *
117
+ * Bzip2.uncompress Bzip2.compress('asdf') # => 'asdf'
118
+ *
119
+ * @param [String] data bz2 compressed data
120
+ * @return [String] +data+ as uncompressed bz2 data
121
+ * @raise [Bzip2::Error] if +data+ is not valid bz2 data
122
+ */
123
+ VALUE bz_uncompress(VALUE self, VALUE data) {
124
+ VALUE bz2, nilv = Qnil, argv[1];
125
+
126
+ argv[0] = rb_str_to_str(data);
127
+ bz2 = rb_funcall2(bz_cReader, id_new, 1, argv);
128
+ return bz_reader_read(1, &nilv, bz2);
129
+ }
130
+
131
+ /*
132
+ * Internally allocates data,
133
+ *
134
+ * @see Bzip2::Writer#initialize
135
+ * @see Bzip2::Reader#initialize
136
+ * @private
137
+ */
138
+ VALUE bz_s_new(int argc, VALUE *argv, VALUE obj) {
139
+ VALUE res = rb_funcall2(obj, rb_intern("allocate"), 0, 0);
140
+ rb_obj_call_init(res, argc, argv);
141
+ return res;
142
+ }
143
+
144
+ void Init_bzip2() {
145
+ VALUE bz_mBzip2, bz_mBzip2Singleton;
146
+
147
+ bz_internal_ary = rb_ary_new();
148
+ rb_global_variable(&bz_internal_ary);
149
+ rb_set_end_proc(bz_internal_finalize, Qnil);
150
+
151
+ id_new = rb_intern("new");
152
+ id_write = rb_intern("write");
153
+ id_open = rb_intern("open");
154
+ id_flush = rb_intern("flush");
155
+ id_read = rb_intern("read");
156
+ id_close = rb_intern("close");
157
+ id_closed = rb_intern("closed?");
158
+ id_str = rb_intern("to_str");
159
+
160
+ bz_mBzip2 = rb_define_module("Bzip2");
161
+ bz_eError = rb_define_class_under(bz_mBzip2, "Error", rb_eIOError);
162
+ bz_eEOZError = rb_define_class_under(bz_mBzip2, "EOZError", bz_eError);
163
+
164
+ bz_mBzip2Singleton = rb_singleton_class(bz_mBzip2);
165
+ rb_define_singleton_method(bz_mBzip2, "compress", bz_compress, 1);
166
+ rb_define_singleton_method(bz_mBzip2, "uncompress", bz_uncompress, 1);
167
+ rb_define_alias(bz_mBzip2Singleton, "bzip2", "compress");
168
+ rb_define_alias(bz_mBzip2Singleton, "decompress", "uncompress");
169
+ rb_define_alias(bz_mBzip2Singleton, "bunzip2", "uncompress");
170
+
171
+ /*
172
+ Writer
173
+ */
174
+ bz_cWriter = rb_define_class_under(bz_mBzip2, "Writer", rb_cData);
175
+ #if HAVE_RB_DEFINE_ALLOC_FUNC
176
+ rb_define_alloc_func(bz_cWriter, bz_writer_s_alloc);
177
+ #else
178
+ rb_define_singleton_method(bz_cWriter, "allocate", bz_writer_s_alloc, 0);
179
+ #endif
180
+ rb_define_singleton_method(bz_cWriter, "new", bz_s_new, -1);
181
+ rb_define_singleton_method(bz_cWriter, "open", bz_writer_s_open, -1);
182
+ rb_define_method(bz_cWriter, "initialize", bz_writer_init, -1);
183
+ rb_define_method(bz_cWriter, "write", bz_writer_write, 1);
184
+ rb_define_method(bz_cWriter, "putc", bz_writer_putc, 1);
185
+ rb_define_method(bz_cWriter, "puts", rb_io_puts, -1);
186
+ rb_define_method(bz_cWriter, "print", rb_io_print, -1);
187
+ rb_define_method(bz_cWriter, "printf", rb_io_printf, -1);
188
+ rb_define_method(bz_cWriter, "<<", rb_io_addstr, 1);
189
+ rb_define_method(bz_cWriter, "flush", bz_writer_flush, 0);
190
+ rb_define_method(bz_cWriter, "close", bz_writer_close, 0);
191
+ rb_define_method(bz_cWriter, "close!", bz_writer_close_bang, 0);
192
+ rb_define_method(bz_cWriter, "closed?", bz_writer_closed, 0);
193
+ rb_define_method(bz_cWriter, "to_io", bz_to_io, 0);
194
+ rb_define_alias(bz_cWriter, "finish", "flush");
195
+ rb_define_alias(bz_cWriter, "closed", "closed?");
196
+
197
+ /*
198
+ Reader
199
+ */
200
+ bz_cReader = rb_define_class_under(bz_mBzip2, "Reader", rb_cData);
201
+ rb_include_module(bz_cReader, rb_mEnumerable);
202
+ #if HAVE_RB_DEFINE_ALLOC_FUNC
203
+ rb_define_alloc_func(bz_cReader, bz_reader_s_alloc);
204
+ #else
205
+ rb_define_singleton_method(bz_cReader, "allocate", bz_reader_s_alloc, 0);
206
+ #endif
207
+ rb_define_singleton_method(bz_cReader, "new", bz_s_new, -1);
208
+ rb_define_singleton_method(bz_cReader, "open", bz_reader_s_open, -1);
209
+ rb_define_singleton_method(bz_cReader, "foreach", bz_reader_s_foreach, -1);
210
+ rb_define_singleton_method(bz_cReader, "readlines", bz_reader_s_readlines, -1);
211
+ rb_define_method(bz_cReader, "initialize", bz_reader_init, -1);
212
+ rb_define_method(bz_cReader, "read", bz_reader_read, -1);
213
+ rb_define_method(bz_cReader, "unused", bz_reader_unused, 0);
214
+ rb_define_method(bz_cReader, "unused=", bz_reader_set_unused, 1);
215
+ rb_define_method(bz_cReader, "ungetc", bz_reader_ungetc, 1);
216
+ rb_define_method(bz_cReader, "ungets", bz_reader_ungets, 1);
217
+ rb_define_method(bz_cReader, "getc", bz_reader_getc, 0);
218
+ rb_define_method(bz_cReader, "gets", bz_reader_gets_m, -1);
219
+ rb_define_method(bz_cReader, "readchar", bz_reader_readchar, 0);
220
+ rb_define_method(bz_cReader, "readline", bz_reader_readline, -1);
221
+ rb_define_method(bz_cReader, "readlines", bz_reader_readlines, -1);
222
+ rb_define_method(bz_cReader, "each", bz_reader_each_line, -1);
223
+ rb_define_method(bz_cReader, "each_byte", bz_reader_each_byte, 0);
224
+ rb_define_method(bz_cReader, "close", bz_reader_close, 0);
225
+ rb_define_method(bz_cReader, "close!", bz_reader_close_bang, 0);
226
+ rb_define_method(bz_cReader, "finish", bz_reader_finish, 0);
227
+ rb_define_method(bz_cReader, "closed?", bz_reader_closed, 0);
228
+ rb_define_method(bz_cReader, "eoz?", bz_reader_eoz, 0);
229
+ rb_define_method(bz_cReader, "eof?", bz_reader_eof, 0);
230
+ rb_define_method(bz_cReader, "lineno", bz_reader_lineno, 0);
231
+ rb_define_method(bz_cReader, "lineno=", bz_reader_set_lineno, 1);
232
+ rb_define_method(bz_cReader, "to_io", bz_to_io, 0);
233
+ rb_define_alias(bz_cReader, "each_line", "each");
234
+ rb_define_alias(bz_cReader, "closed", "closed?");
235
+ rb_define_alias(bz_cReader, "eoz", "eoz?");
236
+ rb_define_alias(bz_cReader, "eof", "eof?");
237
+
238
+ /*
239
+ Internal
240
+ */
241
+ bz_cInternal = rb_define_class_under(bz_mBzip2, "InternalStr", rb_cData);
242
+ #if HAVE_RB_DEFINE_ALLOC_FUNC
243
+ rb_undef_alloc_func(bz_cInternal);
244
+ #else
245
+ rb_undef_method(CLASS_OF(bz_cInternal), "allocate");
246
+ #endif
247
+ rb_undef_method(CLASS_OF(bz_cInternal), "new");
248
+ rb_undef_method(bz_cInternal, "initialize");
249
+ rb_define_method(bz_cInternal, "read", bz_str_read, -1);
250
+ }