File: jedzip.rb

package info (click to toggle)
jed-extra 2.5.7-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 2,972 kB
  • ctags: 2,490
  • sloc: makefile: 75; ruby: 43; sed: 38; sh: 31
file content (55 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# jedzip.rb
# 
# $Id: jedzip.rb,v 1.3 2008/10/27 17:05:21 paul Exp paul $
# 
# Copyright (c) 2008 Paul Boekholt.
# Released under the terms of the GNU GPL (version 2 or later).

require 'zip/zipfilesystem'
SLang.import_namespace "listing", "Listing"

class Zip::Jed < Zip::ZipFile
  include SLang
  include SLang::Listing
  def list
    set_readonly 0
    begin
      erase_buffer
      entries.sort.each{|f| insert(f.to_s + "\n")}
      set_buffer_modified_flag 0
      bob
    ensure
      set_readonly 1
    end
  end
  
  def view_member(filename)
    buffername = "Zip: #{filename}"
    if bufferp(buffername)[0] == 1
      pop2buf buffername
      return
    end
    pop2buf buffername
    contents = file.open(filename) {|f| f.read}
    if contents =~ /\r\n/
      contents.gsub!(/\r\n/, "\n")
      # Set CR mode
      info = getbuf_info
      info[3] |= 0x400
      setbuf_info *info
    end
    insert contents
    bob
  end
  
  def extract_member(filename, dest)
    dest = File.join(dest, File.basename(filename)) if File.directory? dest
    begin
      extract(filename, dest) {
	get_confirmation("#{dest} exists. Overwrite")
      }
    rescue Zip::ZipDestinationFileExistsError
    end
  end
end