Class: PPTX::OPC::FilePart

Inherits:
BinaryPart show all
Defined in:
lib/pptx/opc/file_part.rb

Instance Method Summary collapse

Methods inherited from BinaryPart

#doc

Methods inherited from BasePart

#base_xml, #content_type, #doc, #part_name, #template

Constructor Details

#initialize(package, file) ⇒ FilePart

Returns a new instance of FilePart.



4
5
6
7
8
# File 'lib/pptx/opc/file_part.rb', line 4

def initialize(package, file)
  super(package, File.basename(file))
  @file = file
  @chunk_size = 16 * 1024
end

Instance Method Details

#marshalObject



10
11
12
# File 'lib/pptx/opc/file_part.rb', line 10

def marshal
  IO.read(@file)
end

#sizeObject



14
15
16
# File 'lib/pptx/opc/file_part.rb', line 14

def size
  File.size(@file)
end

#stream(out) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/pptx/opc/file_part.rb', line 18

def stream(out)
  File.open(@file, 'r') do |file|
    while chunk = file.read(@chunk_size)
      puts "Streaming file: #{chunk && chunk.bytesize} bytes"
      out << chunk
    end
  end
end