Class: Sanguinews::FileToUpload
- Inherits:
-
File
- Object
- File
- Sanguinews::FileToUpload
- Defined in:
- lib/sanguinews/file_to_upload.rb
Constant Summary collapse
- @@max_mem =
nil
Instance Attribute Summary collapse
-
#chunks ⇒ Object
Returns the value of attribute chunks.
-
#cname ⇒ Object
readonly
Returns the value of attribute cname.
-
#crc32 ⇒ Object
readonly
Returns the value of attribute crc32.
-
#dir_prefix ⇒ Object
readonly
Returns the value of attribute dir_prefix.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nzb ⇒ Object
readonly
Returns the value of attribute nzb.
-
#subject ⇒ Object
Returns the value of attribute subject.
Instance Method Summary collapse
- #close(last = false) ⇒ Object
- #file_crc32 ⇒ Object
-
#initialize(var) ⇒ FileToUpload
constructor
A new instance of FileToUpload.
- #write_segment_info(length, chunk, msgid) ⇒ Object
Constructor Details
#initialize(var) ⇒ FileToUpload
Returns a new instance of FileToUpload.
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 29 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) max_mem if var[:nzb] @from = var[:from] @groups = var[:groups] nzb_init end return @name end |
Instance Attribute Details
#chunks ⇒ Object
Returns the value of attribute chunks.
24 25 26 |
# File 'lib/sanguinews/file_to_upload.rb', line 24 def chunks @chunks end |
#cname ⇒ Object (readonly)
Returns the value of attribute cname.
25 26 27 |
# File 'lib/sanguinews/file_to_upload.rb', line 25 def cname @cname end |
#crc32 ⇒ Object (readonly)
Returns the value of attribute crc32.
25 26 27 |
# File 'lib/sanguinews/file_to_upload.rb', line 25 def crc32 @crc32 end |
#dir_prefix ⇒ Object (readonly)
Returns the value of attribute dir_prefix.
25 26 27 |
# File 'lib/sanguinews/file_to_upload.rb', line 25 def dir_prefix @dir_prefix end |
#name ⇒ Object
Returns the value of attribute name.
24 25 26 |
# File 'lib/sanguinews/file_to_upload.rb', line 24 def name @name end |
#nzb ⇒ Object (readonly)
Returns the value of attribute nzb.
25 26 27 |
# File 'lib/sanguinews/file_to_upload.rb', line 25 def nzb @nzb end |
#subject ⇒ Object
Returns the value of attribute subject.
24 25 26 |
# File 'lib/sanguinews/file_to_upload.rb', line 24 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. @nzb. if @filemode || last end super() end |
#file_crc32 ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sanguinews/file_to_upload.rb', line 62 def file_crc32 @crc32 ||= begin fcrc32 = nil until self.eof? f = self.read(@@max_mem) crc32 = Zlib.crc32(f, 0) fcrc32 &&= Zlib.crc32_combine(fcrc32, crc32, f.size) fcrc32 ||= crc32 end self.rewind fcrc32.to_s(16) end 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 |