8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/git-media/filter-clean.rb', line 8
def self.run!
media_buffer = GitMedia.get_media_buffer
hashfunc = Digest::SHA1.new
start = Time.now
tempfile = Tempfile.new('media')
while data = STDIN.read(4096)
hashfunc.update(data)
tempfile.write(data)
end
tempfile.close
STDOUT.print hx = hashfunc.hexdigest
STDOUT.binmode
STDOUT.write("\n")
media_file = File.join(media_buffer, hx)
FileUtils.mv(tempfile.path, media_file)
elapsed = Time.now - start
STDERR.puts('Saving media : ' + hx + ' : ' + elapsed.to_s)
end
|