zipruby 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of zipruby might be problematic. Click here for more details.

data/README.txt CHANGED
@@ -73,7 +73,7 @@ https://rubyforge.org/frs/?group_id=6124
73
73
 
74
74
  # add file to zip archive from File object
75
75
  open('bar.txt') do |f|
76
- ar << f # or ar.add_filep(f)
76
+ ar << f # or ar.add_io(f)
77
77
  end
78
78
 
79
79
  # add file to zip archive from buffer
@@ -86,7 +86,7 @@ https://rubyforge.org/frs/?group_id=6124
86
86
  # args: <entry name>, <source>
87
87
 
88
88
  open('bar.txt') do |f|
89
- ar.add_filep('dirname/bar.txt', f)
89
+ ar.add_io('dirname/bar.txt', f)
90
90
  # args: <entry name>, <source>
91
91
  end
92
92
 
@@ -114,7 +114,7 @@ https://rubyforge.org/frs/?group_id=6124
114
114
 
115
115
  # replace file in zip archive with File object
116
116
  open('bar.txt') do |f|
117
- ar.replace_filep(1, f)
117
+ ar.replace_io(1, f)
118
118
  end
119
119
 
120
120
  # if commit changes
@@ -165,6 +165,39 @@ https://rubyforge.org/frs/?group_id=6124
165
165
  # ar.decrypt('filename.zip', 'password')
166
166
  # end
167
167
 
168
+ === modifying zip data in memory
169
+
170
+ require 'zipruby'
171
+
172
+ $stdout.binmode
173
+
174
+ buf = ''
175
+
176
+ Zip::Archive.open_buffer(buf, Zip::CREATE) do |ar|
177
+ ar.add_buffer('bar.txt', 'zoo');
178
+ end
179
+
180
+ Zip::Archive.open_buffer(buf) do |ar|
181
+ ar.each do |f|
182
+ puts f.name
183
+ end
184
+ end
185
+
186
+ # read from stream
187
+ zip_data = open('foo.zip').raed
188
+ stream = lambda { return !zip_data.slice(0, 256) }
189
+
190
+ Zip::Archive.open_buffer(stream) do |ar|
191
+ puts ar.num_files
192
+ end
193
+
194
+ # output huge zip data to stdout
195
+ Zip::Archive.open_buffer(zip_data) do |ar|
196
+ ar.read do |chunk|
197
+ print chunk
198
+ end
199
+ end
200
+
168
201
  == License
169
202
  Copyright (c) 2008 SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
170
203
  All rights reserved.
@@ -2,7 +2,7 @@
2
2
  <VisualStudioUserFile
3
3
  ProjectType="Visual C++"
4
4
  Version="9.00"
5
- ShowAllFiles="true"
5
+ ShowAllFiles="false"
6
6
  >
7
7
  <Configurations>
8
8
  <Configuration
@@ -15,7 +15,7 @@
15
15
  Attach="false"
16
16
  DebuggerType="3"
17
17
  Remote="1"
18
- RemoteMachine="IBM-62EEBFAE94C"
18
+ RemoteMachine="LENOVO-72DB7FA8"
19
19
  RemoteCommand=""
20
20
  HttpUrl=""
21
21
  PDBPath=""
data/ext/tmpfile.c CHANGED
@@ -150,16 +150,16 @@ static int write_from_proc(VALUE proc, int fd) {
150
150
  break;
151
151
  }
152
152
 
153
- if (RSTRING(src)->len < 1) {
153
+ if (RSTRING_LEN(src) < 1) {
154
154
  break;
155
155
  }
156
156
 
157
157
  #ifdef _WIN32
158
- if (_write(fd, StringValuePtr(src), RSTRING(src)->len) == -1) {
158
+ if (_write(fd, RSTRING_PTR(src), RSTRING_LEN(src)) == -1) {
159
159
  return -1;
160
160
  }
161
161
  #else
162
- if (write(fd, StringValuePtr(src), RSTRING(src)->len) == -1) {
162
+ if (write(fd, RSTRING_PTR(src), RSTRING_LEN(src)) == -1) {
163
163
  return -1;
164
164
  }
165
165
  #endif
data/ext/zip_crypt.c CHANGED
@@ -219,6 +219,7 @@ static int copy_encrypt(FILE *src, off_t len, const char *pwd, int pwdlen, struc
219
219
  }
220
220
 
221
221
  static int _zip_crypt(struct zip *za, const char *pwd, int pwdlen, int decrypt, int *wrongpwd) {
222
+ int translated = 0;
222
223
  int i, error = 0;
223
224
  char *temp;
224
225
  FILE *out;
@@ -296,11 +297,13 @@ static int _zip_crypt(struct zip *za, const char *pwd, int pwdlen, int decrypt,
296
297
  de.bitflags &= ~ZIP_GPBF_ENCRYPTED;
297
298
  cd->entry[i].comp_size -= ZIPENC_HEAD_LEN;
298
299
  cd->entry[i].bitflags &= ~ZIP_GPBF_ENCRYPTED;
300
+ translated = 1;
299
301
  } else if (!decrypt && !encrypted) {
300
302
  de.comp_size += ZIPENC_HEAD_LEN;
301
303
  de.bitflags |= ZIP_GPBF_ENCRYPTED;
302
304
  cd->entry[i].comp_size += ZIPENC_HEAD_LEN;
303
305
  cd->entry[i].bitflags |= ZIP_GPBF_ENCRYPTED;
306
+ translated = 1;
304
307
  }
305
308
 
306
309
  if (_zip_dirent_write(&de, out, 1, &za->error) < 0) {
@@ -370,7 +373,7 @@ static int _zip_crypt(struct zip *za, const char *pwd, int pwdlen, int decrypt,
370
373
  #endif
371
374
 
372
375
  free(temp);
373
- return 0;
376
+ return translated;
374
377
  }
375
378
 
376
379
  int zip_decrypt(const char *path, const char *pwd, int pwdlen, int *errorp, int *wrongpwd) {
data/ext/zipruby.h CHANGED
@@ -1,7 +1,22 @@
1
1
  #ifndef __ZIPRUBY_H__
2
2
  #define __ZIPRUBY_H__
3
3
 
4
- #define VERSION "0.2.8"
4
+ #include "ruby.h"
5
+
6
+ #ifndef RSTRING_PTR
7
+ #define RSTRING_PTR(s) (RSTRING(s)->ptr)
8
+ #endif
9
+ #ifndef RSTRING_LEN
10
+ #define RSTRING_LEN(s) (RSTRING(s)->len)
11
+ #endif
12
+
13
+ #define Check_IO(x) do { \
14
+ if (!rb_obj_is_instance_of((x), rb_cIO)) { \
15
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected IO)", rb_class2name(CLASS_OF(x))); \
16
+ } \
17
+ } while(0)
18
+
19
+ #define VERSION "0.2.9"
5
20
  #define ERRSTR_BUFSIZE 256
6
21
  #define DATA_BUFSIZE 8192
7
22