squeezem 0.1.1 → 0.1.2
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.
- data/lib/squeezem.rb +19 -12
- metadata +4 -4
data/lib/squeezem.rb
CHANGED
@@ -7,27 +7,37 @@ require 'fileutils'
|
|
7
7
|
class Squeezem
|
8
8
|
def initialize(options)
|
9
9
|
@options = options
|
10
|
-
@output_path = "/tmp/x"
|
11
10
|
@total_bytes = 0
|
12
11
|
@saved_bytes = 0
|
13
12
|
@files_seen = 0
|
14
13
|
@files_ignored = 0
|
15
14
|
@files_with_saving = 0
|
16
|
-
output_dir =
|
15
|
+
output_dir = make_output_dir
|
17
16
|
at_exit do
|
18
17
|
write_cache
|
19
18
|
FileUtils.rm_rf(output_dir)
|
20
19
|
end
|
21
20
|
@output_path = File.join(output_dir, 'x')
|
22
21
|
@files = read_cache
|
23
|
-
@interrupted = false
|
24
22
|
trap("INT") {
|
25
|
-
|
23
|
+
summary
|
24
|
+
exit
|
26
25
|
}
|
27
26
|
end
|
28
27
|
|
28
|
+
def make_output_dir
|
29
|
+
begin
|
30
|
+
Dir.mktmpdir
|
31
|
+
rescue NoMethodError
|
32
|
+
# Lame fallback for 1.8.6-p369 and below
|
33
|
+
dir = Dir.tmpdir + "/squeezem-#{$$}"
|
34
|
+
Dir.mkdir(dir)
|
35
|
+
FileUtils.chmod(0700, dir)
|
36
|
+
return dir
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
29
40
|
def squeeze(path)
|
30
|
-
handle_interruption
|
31
41
|
return unless valid_file?(path)
|
32
42
|
@files_seen += 1
|
33
43
|
@path = path
|
@@ -48,6 +58,10 @@ class Squeezem
|
|
48
58
|
end
|
49
59
|
if File.exist?(@output_path)
|
50
60
|
new_size = File.size(@output_path)
|
61
|
+
if new_size == 0
|
62
|
+
$stderr.puts "Empty output for #{path}"
|
63
|
+
return
|
64
|
+
end
|
51
65
|
saving = @size - new_size
|
52
66
|
record_saving(saving)
|
53
67
|
@files[canonical_path] = OpenStruct.new(:size => @size, :saving => saving)
|
@@ -57,13 +71,6 @@ class Squeezem
|
|
57
71
|
end
|
58
72
|
end
|
59
73
|
|
60
|
-
def handle_interruption
|
61
|
-
if @interrupted
|
62
|
-
summary
|
63
|
-
exit
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
74
|
def valid_file?(path)
|
68
75
|
if !(path =~ /\.(png)$/)
|
69
76
|
@files_ignored += 1
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squeezem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Steve Woodcock
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-23 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|