Class: Zip::ZipOutputStream

Inherits:
Object show all
Includes:
IOExtras::AbstractOutputStream
Defined in:
lib/zip/zip.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IOExtras::AbstractOutputStream

#print, #printf, #putc, #puts, #write

Methods included from IOExtras::FakeIO

#kind_of?

Constructor Details

#initialize(fileName) ⇒ ZipOutputStream

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

#commentObject

Returns the value of attribute comment.



512
513
514
# File 'lib/zip/zip.rb', line 512

def comment
  @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

#<<(data) ⇒ Object



617
618
619
# File 'lib/zip/zip.rb', line 617

def << (data)
  @compressor << data
end

#closeObject



533
534
535
536
537
538
539
540
# File 'lib/zip/zip.rb', line 533

def close
  return if @closed
  finalize_current_entry
  update_local_headers
  write_central_directory
  @outputStream.close
  @closed = true
end

#copy_raw_entry(entry) ⇒ Object

Raises:



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

Raises:



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