openzip 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d782876191942de007cd5fbeba85699ed89ad948
4
- data.tar.gz: d8997aedd007cf5600bf473672d37fc833e9dcf2
3
+ metadata.gz: 28f35c556ac7fb2a8da1d85a2e8ccb5c92ffb4a0
4
+ data.tar.gz: 614e70bb91dd1ba2ee354c51eaf31f8cffb49ffd
5
5
  SHA512:
6
- metadata.gz: 135a337be864c4664c349c208a6abfe6d030f8a6ad9d9b9880f41610ac8fd74d4f93942f85580f7647403e5a1dbf195b3e9a2ce881c47d340589e25fcdde1bd8
7
- data.tar.gz: fa2b24b6e6272466ca675b83e31ef7831042f1ffdf3a55d31a94886242f253ea522b2cd142ed38c4475383db19727911021ba7e9598146990e0c1f8bb0d380d7
6
+ metadata.gz: 9ebc742c30c9de79bdfc068156e00b16701ef05b44d2ee8bba1ec334a40e8080b3112b0fdfcbe82de4672b28373041766d9e077313993bec9e946fa88eae26b0
7
+ data.tar.gz: 6431ed512cff3b0981fb504b08a356d9d250b468d614fd7227f9ce0dbeeece8a2fe995ee4216d1fdbb091dea01a20a6cbe5c3b888af2050618a54a9d5afb4572
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ *.gem
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
@@ -7,3 +8,4 @@
7
8
  /pkg/
8
9
  /spec/reports/
9
10
  /tmp/
11
+ /source/target/
data/.simplecov ADDED
@@ -0,0 +1,3 @@
1
+ SimpleCov.start do
2
+ add_filter "spec"
3
+ end
data/.travis.yml CHANGED
@@ -1,11 +1,13 @@
1
1
  language: ruby
2
2
  cache: bundler
3
+ sudo: required
3
4
 
4
5
  rvm:
5
6
  - 2.3.0
6
7
 
7
8
  before_install:
8
9
  - gem install bundler -v 1.13.6
10
+ - bin/compile
9
11
 
10
12
  script:
11
13
  - bin/ci
data/Gemfile CHANGED
@@ -7,3 +7,8 @@ group :development, :test do
7
7
  gem "bundler-audit", require: false
8
8
  gem "rubocop-rspec", require: false
9
9
  end
10
+
11
+ group :test do
12
+ gem "codeclimate-test-reporter", "~> 1.0.0", require: false
13
+ gem "simplecov", require: false
14
+ end
data/README.md CHANGED
@@ -1,8 +1,21 @@
1
1
  # Openzip
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/openzip`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://img.shields.io/travis/ilyasgaraev/openzip.svg?branch=master&style=flat-square)](https://travis-ci.org/ilyasgaraev/openzip)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/ilyasgaraev/openzip.svg?style=flat-square)](https://codeclimate.com/github/ilyasgaraev/openzip)
5
+ [![Test Coverage](https://img.shields.io/codeclimate/coverage/github/ilyasgaraev/openzip.svg?style=flat-square)](https://codeclimate.com/github/ilyasgaraev/openzip/coverage)
6
+ [![Gem](https://img.shields.io/gem/v/openzip.svg?style=flat-square)](https://github.com/ilyasgaraev/openzip)
4
7
 
5
- TODO: Delete this and the text above, and describe your gem
8
+
9
+ **Openzip** is a Ruby library for fast extract Zip files.
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ path_to_zip = "path/to/zipfile.zip"
15
+ extract_to_path = "path/to/extract"
16
+
17
+ Openzip.extract(path_to_zip, extract_to_path)
18
+ ```
6
19
 
7
20
  ## Installation
8
21
 
@@ -20,22 +33,11 @@ Or install it yourself as:
20
33
 
21
34
  $ gem install openzip
22
35
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
36
  ## Contributing
34
37
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/openzip. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ilyasgaraev/openzip. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
39
 
37
40
 
38
41
  ## License
39
42
 
40
43
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
data/bin/compile ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env sh
2
+
3
+ set -e
4
+
5
+ curl -sSf https://static.rust-lang.org/rustup.sh | sh
6
+ cd source && make
data/lib/openzip.rb CHANGED
@@ -1,5 +1,15 @@
1
- require "openzip/version"
1
+ require "fiddle"
2
+ require "fiddle/import"
2
3
 
3
4
  module Openzip
4
- # Your code goes here...
5
+ extend Fiddle::Importer
6
+
7
+ def self.lib_ext
8
+ raise "Sorry, windows is not supported yet" if RUBY_PLATFORM =~ /win32/
9
+
10
+ RUBY_PLATFORM =~ /darwin/ ? "dylib" : "so"
11
+ end
12
+
13
+ dlload "#{File.dirname(__FILE__)}/../source/target/release/libopenzip.#{lib_ext}"
14
+ extern "void extract(char*, char*)"
5
15
  end
@@ -1,3 +1,3 @@
1
1
  module Openzip
2
- VERSION = "0.0.0".freeze
2
+ VERSION = "0.1.0".freeze
3
3
  end
data/openzip.gemspec CHANGED
@@ -16,8 +16,11 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^spec/})
19
20
  spec.require_paths = ["lib"]
20
21
 
22
+ spec.extensions = Dir["source/extconf.rb"]
23
+
21
24
  spec.add_development_dependency "bundler", "~> 1.13"
22
25
  spec.add_development_dependency "pry", "~> 0.10"
23
26
  spec.add_development_dependency "rake", "~> 10.0"
data/source/Cargo.lock ADDED
@@ -0,0 +1,131 @@
1
+ [root]
2
+ name = "openzip"
3
+ version = "0.1.0"
4
+ dependencies = [
5
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
6
+ "zip 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
7
+ ]
8
+
9
+ [[package]]
10
+ name = "bzip2"
11
+ version = "0.3.1"
12
+ source = "registry+https://github.com/rust-lang/crates.io-index"
13
+ dependencies = [
14
+ "bzip2-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
15
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
16
+ ]
17
+
18
+ [[package]]
19
+ name = "bzip2-sys"
20
+ version = "0.1.5"
21
+ source = "registry+https://github.com/rust-lang/crates.io-index"
22
+ dependencies = [
23
+ "gcc 0.3.41 (registry+https://github.com/rust-lang/crates.io-index)",
24
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
25
+ ]
26
+
27
+ [[package]]
28
+ name = "flate2"
29
+ version = "0.2.17"
30
+ source = "registry+https://github.com/rust-lang/crates.io-index"
31
+ dependencies = [
32
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
33
+ "miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
34
+ ]
35
+
36
+ [[package]]
37
+ name = "gcc"
38
+ version = "0.3.41"
39
+ source = "registry+https://github.com/rust-lang/crates.io-index"
40
+
41
+ [[package]]
42
+ name = "kernel32-sys"
43
+ version = "0.2.2"
44
+ source = "registry+https://github.com/rust-lang/crates.io-index"
45
+ dependencies = [
46
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
47
+ "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
48
+ ]
49
+
50
+ [[package]]
51
+ name = "libc"
52
+ version = "0.2.20"
53
+ source = "registry+https://github.com/rust-lang/crates.io-index"
54
+
55
+ [[package]]
56
+ name = "miniz-sys"
57
+ version = "0.1.9"
58
+ source = "registry+https://github.com/rust-lang/crates.io-index"
59
+ dependencies = [
60
+ "gcc 0.3.41 (registry+https://github.com/rust-lang/crates.io-index)",
61
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
62
+ ]
63
+
64
+ [[package]]
65
+ name = "msdos_time"
66
+ version = "0.1.4"
67
+ source = "registry+https://github.com/rust-lang/crates.io-index"
68
+ dependencies = [
69
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
70
+ "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
71
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
72
+ ]
73
+
74
+ [[package]]
75
+ name = "podio"
76
+ version = "0.1.5"
77
+ source = "registry+https://github.com/rust-lang/crates.io-index"
78
+
79
+ [[package]]
80
+ name = "redox_syscall"
81
+ version = "0.1.16"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+
84
+ [[package]]
85
+ name = "time"
86
+ version = "0.1.36"
87
+ source = "registry+https://github.com/rust-lang/crates.io-index"
88
+ dependencies = [
89
+ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
90
+ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
91
+ "redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
92
+ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
93
+ ]
94
+
95
+ [[package]]
96
+ name = "winapi"
97
+ version = "0.2.8"
98
+ source = "registry+https://github.com/rust-lang/crates.io-index"
99
+
100
+ [[package]]
101
+ name = "winapi-build"
102
+ version = "0.1.1"
103
+ source = "registry+https://github.com/rust-lang/crates.io-index"
104
+
105
+ [[package]]
106
+ name = "zip"
107
+ version = "0.2.0"
108
+ source = "registry+https://github.com/rust-lang/crates.io-index"
109
+ dependencies = [
110
+ "bzip2 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
111
+ "flate2 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
112
+ "msdos_time 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
113
+ "podio 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
114
+ "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
115
+ ]
116
+
117
+ [metadata]
118
+ "checksum bzip2 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e39c71fcff507b547240346a894c5df38e6fd42fb02590a5d5b3f2dae9173ad2"
119
+ "checksum bzip2-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "98ce3fff84d4e90011f464bbdf48e3428f04270439f703868fd489d2aaedfc30"
120
+ "checksum flate2 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "d4e4d0c15ef829cbc1b7cda651746be19cceeb238be7b1049227b14891df9e25"
121
+ "checksum gcc 0.3.41 (registry+https://github.com/rust-lang/crates.io-index)" = "3689e1982a563af74960ae3a4758aa632bb8fd984cfc3cc3b60ee6109477ab6e"
122
+ "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
123
+ "checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5"
124
+ "checksum miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "28eaee17666671fa872e567547e8428e83308ebe5808cdf6a0e28397dbe2c726"
125
+ "checksum msdos_time 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c04b68cc63a8480fb2550343695f7be72effdec953a9d4508161c3e69041c7d8"
126
+ "checksum podio 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e5422a1ee1bc57cc47ae717b0137314258138f38fd5f3cea083f43a9725383a0"
127
+ "checksum redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd35cc9a8bdec562c757e3d43c1526b5c6d2653e23e2315065bc25556550753"
128
+ "checksum time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "211b63c112206356ef1ff9b19355f43740fc3f85960c598a93d3a3d3ba7beade"
129
+ "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
130
+ "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
131
+ "checksum zip 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02b92cddcdaa29487e3eb80061fd9942f03e1a27d1a4b342a502331d9b64dc22"
data/source/Cargo.toml ADDED
@@ -0,0 +1,12 @@
1
+ [package]
2
+ name = "openzip"
3
+ version = "0.1.0"
4
+ authors = ["Ilyas Garaev <vearagi@gmail.com>"]
5
+
6
+ [dependencies]
7
+ zip = "0.2"
8
+ libc = "0.2"
9
+
10
+ [lib]
11
+ name = "openzip"
12
+ crate-type = ["dylib"]
data/source/Makefile ADDED
@@ -0,0 +1,7 @@
1
+ all:
2
+ cargo build --release
3
+
4
+ clean:
5
+ rm -rf target
6
+
7
+ install: ;
data/source/extconf.rb ADDED
@@ -0,0 +1,3 @@
1
+ unless system("cargo --version") || system("rustc --version")
2
+ raise "You have to install Rust with Cargo (https://www.rust-lang.org/)"
3
+ end
data/source/src/lib.rs ADDED
@@ -0,0 +1,94 @@
1
+ extern crate zip;
2
+ extern crate libc;
3
+
4
+ use std::io;
5
+ use std::fs;
6
+ use std::path::{Path, PathBuf, Component};
7
+ use std::ffi::CStr;
8
+
9
+ #[cfg(unix)]
10
+ use std::os::unix::fs::PermissionsExt;
11
+
12
+ #[no_mangle]
13
+ pub extern fn extract(zippath: *const libc::c_char, outdirpath: *const libc::c_char) {
14
+ let zname = Path::new(rust_string(zippath));
15
+ let outdir = Path::new(rust_string(outdirpath));
16
+
17
+ create_directory(&outdir, None);
18
+ let file = fs::File::open(&zname).unwrap();
19
+
20
+ let mut archive = zip::ZipArchive::new(file).unwrap();
21
+
22
+ for i in 0..archive.len()
23
+ {
24
+ let mut file = archive.by_index(i).unwrap();
25
+ let outpath = sanitize_filename(file.name(), outdir);
26
+
27
+ create_directory(outpath.parent().unwrap_or(Path::new("")), None);
28
+
29
+ let perms = convert_permissions(file.unix_mode());
30
+
31
+ if (&*file.name()).ends_with("/") {
32
+ create_directory(&outpath, perms);
33
+ }
34
+ else {
35
+ write_file(&mut file, &outpath, perms);
36
+ }
37
+ }
38
+ }
39
+
40
+ fn rust_string(r_string: *const libc::c_char) -> &'static str {
41
+ unsafe { CStr::from_ptr(r_string) }.to_str().unwrap()
42
+ }
43
+
44
+ #[cfg(unix)]
45
+ fn convert_permissions(mode: Option<u32>) -> Option<fs::Permissions>
46
+ {
47
+ match mode {
48
+ Some(mode) => Some(fs::Permissions::from_mode(mode)),
49
+ None => None,
50
+ }
51
+ }
52
+
53
+ #[cfg(not(unix))]
54
+ fn convert_permissions(_mode: Option<u32>) -> Option<fs::Permissions>
55
+ {
56
+ None
57
+ }
58
+
59
+ fn write_file(file: &mut zip::read::ZipFile, outpath: &Path, perms: Option<fs::Permissions>)
60
+ {
61
+ let mut outfile = fs::File::create(&outpath).unwrap();
62
+ io::copy(file, &mut outfile).unwrap();
63
+ if let Some(perms) = perms {
64
+ fs::set_permissions(outpath, perms).unwrap();
65
+ }
66
+ }
67
+
68
+ fn create_directory(outpath: &Path, perms: Option<fs::Permissions>)
69
+ {
70
+ fs::create_dir_all(&outpath).unwrap();
71
+ if let Some(perms) = perms {
72
+ fs::set_permissions(outpath, perms).unwrap();
73
+ }
74
+ }
75
+
76
+ fn sanitize_filename(filename: &str, outdir: &Path) -> PathBuf
77
+ {
78
+ let no_null_filename = match filename.find('\0') {
79
+ Some(index) => &filename[0..index],
80
+ None => filename,
81
+ };
82
+
83
+ let filepath = Path::new(no_null_filename)
84
+ .components()
85
+ .filter(|component| *component != Component::ParentDir)
86
+ .fold(PathBuf::new(), |mut path, ref cur| {
87
+ path.push(cur.as_os_str());
88
+ path
89
+ });
90
+
91
+ let mut outdirbuf = PathBuf::from(outdir);
92
+ outdirbuf.push(filepath);
93
+ return outdirbuf.to_path_buf();
94
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openzip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilyas Garaev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,19 +72,22 @@ email:
72
72
  executables:
73
73
  - bundle-audit
74
74
  - ci
75
+ - compile
75
76
  - console
76
77
  - quality
77
78
  - rake
78
79
  - rspec
79
80
  - rubocop
80
81
  - setup
81
- extensions: []
82
+ extensions:
83
+ - source/extconf.rb
82
84
  extra_rdoc_files: []
83
85
  files:
84
86
  - ".codeclimate.yml"
85
87
  - ".gitignore"
86
88
  - ".rspec"
87
89
  - ".rubocop.yml"
90
+ - ".simplecov"
88
91
  - ".travis.yml"
89
92
  - Gemfile
90
93
  - LICENSE
@@ -92,6 +95,7 @@ files:
92
95
  - Rakefile
93
96
  - bin/bundle-audit
94
97
  - bin/ci
98
+ - bin/compile
95
99
  - bin/console
96
100
  - bin/quality
97
101
  - bin/rake
@@ -101,6 +105,11 @@ files:
101
105
  - lib/openzip.rb
102
106
  - lib/openzip/version.rb
103
107
  - openzip.gemspec
108
+ - source/Cargo.lock
109
+ - source/Cargo.toml
110
+ - source/Makefile
111
+ - source/extconf.rb
112
+ - source/src/lib.rs
104
113
  homepage: https://github.com/ilyasgaraev/openzip
105
114
  licenses:
106
115
  - MIT