Class: Zip::ZipOutputStream
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#print, #printf, #putc, #puts, #write
#kind_of?
Constructor Details
Returns a new instance of ZipOutputStream.
514
515
516
517
518
519
520
521
522
523
|
# File 'lib/zip/zip.rb', line 514
def initialize(fileName)
super()
@fileName = fileName
@outputStream = File.new(@fileName, "wb")
@entrySet = ZipEntrySet.new
@compressor = NullCompressor.instance
@closed = false
@currentEntry = nil
@comment = nil
end
|
Instance Attribute Details
Returns the value of attribute comment.
512
513
514
|
# File 'lib/zip/zip.rb', line 512
def
@comment
end
|
Class Method Details
.open(fileName) ⇒ Object
525
526
527
528
529
530
531
|
# File 'lib/zip/zip.rb', line 525
def ZipOutputStream.open(fileName)
return new(fileName) unless block_given?
zos = new(fileName)
yield zos
ensure
zos.close if zos
end
|
Instance Method Details
617
618
619
|
# File 'lib/zip/zip.rb', line 617
def << (data)
@compressor << data
end
|
533
534
535
536
537
538
539
540
|
# File 'lib/zip/zip.rb', line 533
def close
return if @closed
finalize_current_entry
write_central_directory
@outputStream.close
@closed = true
end
|
#copy_raw_entry(entry) ⇒ Object
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
|
# File 'lib/zip/zip.rb', line 549
def copy_raw_entry(entry)
entry = entry.dup
raise ZipError, "zip stream is closed" if @closed
raise ZipError, "entry is not a ZipEntry" if !entry.kind_of?(ZipEntry)
finalize_current_entry
@entrySet << entry
src_pos = entry.local_entry_offset
entry.write_local_entry(@outputStream)
@compressor = NullCompressor.instance
@outputStream << entry.get_raw_input_stream {
|is|
is.seek(src_pos, IO::SEEK_SET)
is.read(entry.compressed_size)
}
@compressor = NullCompressor.instance
@currentEntry = nil
end
|
#put_next_entry(entry, level = Zlib::DEFAULT_COMPRESSION) ⇒ Object
542
543
544
545
546
547
|
# File 'lib/zip/zip.rb', line 542
def put_next_entry(entry, level = Zlib::DEFAULT_COMPRESSION)
raise ZipError, "zip stream is closed" if @closed
newEntry = entry.kind_of?(ZipEntry) ? entry : ZipEntry.new(@fileName, entry.to_s)
init_next_entry(newEntry)
@currentEntry=newEntry
end
|