Class: Sanguinews::FileToUpload

Inherits:
File
  • Object
show all
Defined in:
lib/sanguinews/file_to_upload.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(var) ⇒ FileToUpload

Returns a new instance of FileToUpload.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sanguinews/file_to_upload.rb', line 24

def initialize(var)
  @dir_prefix = ''

  var[:mode] = "rb" if var[:mode].nil?

  super(var[:name], var[:mode])
  @filemode = var[:filemode]
  @name = File.basename(var[:name])
  chunk_amount(var[:chunk_length])
  common_name(var)
  @from = var[:from]
  @groups = var[:groups]
  if var[:nzb]
    nzb_init
  end
  @messages = []
  @chunks.times do |x|
	subject = "#{var[:prefix]}#{@dir_prefix}\"#{@name}\" yEnc (#{x+1}/#{@chunks})"
	@messages[x] = NntpMsg.new(@from, @groups, subject)
	@messages[x].xna = var[:xna]
  end
  return @name
end

Instance Attribute Details

#chunksObject

Returns the value of attribute chunks.



21
22
23
# File 'lib/sanguinews/file_to_upload.rb', line 21

def chunks
  @chunks
end

#cnameObject (readonly)

Returns the value of attribute cname.



22
23
24
# File 'lib/sanguinews/file_to_upload.rb', line 22

def cname
  @cname
end

#crc32Object (readonly)

Returns the value of attribute crc32.



22
23
24
# File 'lib/sanguinews/file_to_upload.rb', line 22

def crc32
  @crc32
end

#dir_prefixObject (readonly)

Returns the value of attribute dir_prefix.



22
23
24
# File 'lib/sanguinews/file_to_upload.rb', line 22

def dir_prefix
  @dir_prefix
end

#messagesObject

Returns the value of attribute messages.



21
22
23
# File 'lib/sanguinews/file_to_upload.rb', line 21

def messages
  @messages
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/sanguinews/file_to_upload.rb', line 21

def name
  @name
end

#nzbObject (readonly)

Returns the value of attribute nzb.



22
23
24
# File 'lib/sanguinews/file_to_upload.rb', line 22

def nzb
  @nzb
end

#subjectObject

Returns the value of attribute subject.



21
22
23
# File 'lib/sanguinews/file_to_upload.rb', line 21

def subject
  @subject
end

Instance Method Details

#close(last = false) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/sanguinews/file_to_upload.rb', line 48

def close(last=false)
  if @nzb
    @nzb.write_file_header(@from, @subject, @groups)
    @nzb.write_segments
    @nzb.write_file_footer
    @nzb.write_footer if @filemode || last
  end
  super()
end

#file_crc32Object



62
63
64
65
66
67
68
69
# File 'lib/sanguinews/file_to_upload.rb', line 62

def file_crc32
  fcrc32 = false
  @messages.each do |message|
	fcrc32 &&= Zlib.crc32_combine(fcrc32, message.part_crc32.to_i(16), message.length)
	fcrc32 ||= message.part_crc32.to_i(16)
  end
  @crc32 = fcrc32.to_s(16)
end

#write_segment_info(length, chunk, msgid) ⇒ Object



58
59
60
# File 'lib/sanguinews/file_to_upload.rb', line 58

def write_segment_info(length, chunk, msgid)
  @nzb.save_segment(length, chunk, msgid) if @nzb
end