presso 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/presso.rb +53 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0676312e4ccbb2170348ba9c0b3f09f39cf44811
|
4
|
+
data.tar.gz: b827bd3ad3277dc6de6496b5d46817a6959bdb9c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: acaa585142de00a910fe1cf3209513030854e116c77a754c399df4646bb097fc3a5e95c77a88a2b3b5886aac79702f8d2d2a824e467f49833e7a0c68dc0d3bfe
|
7
|
+
data.tar.gz: b3170a14985018015fb923350d69ae1ad53900c404b24c0de9ef1e8b66215fefab7ba12d831fc5ae28b115701761a38b7e58de99783220f0288210c664db843e
|
data/lib/presso.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'java'
|
2
|
+
|
3
|
+
raise LoadError, "Incompatible JRuby version. Use at least JRuby 1.7.4. See JRUBY-7157." if JRUBY_VERSION =~ /^1\.7\.[0-3]$/
|
4
|
+
|
5
|
+
class Presso
|
6
|
+
VERSION = '1.0.0'.freeze
|
7
|
+
|
8
|
+
module JavaUtilZip
|
9
|
+
include_package 'java.util.zip'
|
10
|
+
end
|
11
|
+
|
12
|
+
PressoError = Class.new(StandardError)
|
13
|
+
|
14
|
+
def zip_dir(output_path, input_directory)
|
15
|
+
output_path = File.expand_path(output_path)
|
16
|
+
Dir.chdir(input_directory) do
|
17
|
+
File.open(output_path, File::WRONLY|File::CREAT|File::EXCL, binmode: true) do |file|
|
18
|
+
stream = JavaUtilZip::ZipOutputStream.new(file.to_outputstream)
|
19
|
+
Dir['**/*'].each do |path|
|
20
|
+
if File.file?(path)
|
21
|
+
stream.putNextEntry(JavaUtilZip::ZipEntry.new(path))
|
22
|
+
IO.copy_stream(path, stream.to_io)
|
23
|
+
elsif File.directory?(path)
|
24
|
+
stream.putNextEntry(JavaUtilZip::ZipEntry.new(path+'/'))
|
25
|
+
else
|
26
|
+
raise PressoError, "File #{path} is not a regular file."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
stream.close
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def unzip(input_path, output_directory)
|
35
|
+
raise PressoError, "Target directory #{output_directory} already exists." if File.exists?(output_directory)
|
36
|
+
File.open(input_path, 'rb') do |file|
|
37
|
+
stream = JavaUtilZip::ZipInputStream.new(file.to_inputstream)
|
38
|
+
FileUtils.mkdir_p(output_directory)
|
39
|
+
Dir.chdir(output_directory) do
|
40
|
+
while (entry = stream.next_entry)
|
41
|
+
if entry.directory?
|
42
|
+
FileUtils.mkdir_p(entry.name)
|
43
|
+
else
|
44
|
+
FileUtils.mkdir_p(File.dirname(entry.name))
|
45
|
+
IO.copy_stream(stream.to_io, entry.name)
|
46
|
+
end
|
47
|
+
stream.close_entry
|
48
|
+
end
|
49
|
+
end
|
50
|
+
stream.close
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: presso
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Burt Developers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Easy zip and unzip, backed by java.util.zip
|
14
|
+
email:
|
15
|
+
- bjorn@burtcorp.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/presso.rb
|
21
|
+
homepage: https://github.com/burtcorp/presso
|
22
|
+
licenses: []
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: A zip library for JRuby
|
44
|
+
test_files: []
|