Class: ZipTricks::FileReader::ZipEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/zip_tricks/file_reader.rb

Overview

Represents a file within the ZIP archive being read

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commentString

Returns the file comment.

Returns:

  • (String)

    the file comment



163
164
165
# File 'lib/zip_tricks/file_reader.rb', line 163

def comment
  @comment
end

#compressed_data_offsetFixnum

Returns at what offset you should start reading for the compressed data in your original IO object.

Returns:

  • (Fixnum)

    at what offset you should start reading for the compressed data in your original IO object



167
168
169
# File 'lib/zip_tricks/file_reader.rb', line 167

def compressed_data_offset
  @compressed_data_offset
end

#compressed_sizeFixnum

Returns size of compressed file data in the ZIP.

Returns:

  • (Fixnum)

    size of compressed file data in the ZIP



141
142
143
# File 'lib/zip_tricks/file_reader.rb', line 141

def compressed_size
  @compressed_size
end

#crc32Fixnum

Returns the CRC32 checksum of this file.

Returns:

  • (Fixnum)

    the CRC32 checksum of this file



138
139
140
# File 'lib/zip_tricks/file_reader.rb', line 138

def crc32
  @crc32
end

#disk_number_startFixnum

Returns disk number where this file starts.

Returns:

  • (Fixnum)

    disk number where this file starts



150
151
152
# File 'lib/zip_tricks/file_reader.rb', line 150

def disk_number_start
  @disk_number_start
end

#dos_dateFixnum

Returns the bit-packed DOS date.

Returns:

  • (Fixnum)

    the bit-packed DOS date



135
136
137
# File 'lib/zip_tricks/file_reader.rb', line 135

def dos_date
  @dos_date
end

#dos_timeFixnum

Returns the bit-packed DOS time.

Returns:

  • (Fixnum)

    the bit-packed DOS time



132
133
134
# File 'lib/zip_tricks/file_reader.rb', line 132

def dos_time
  @dos_time
end

#external_attrsFixnum

Returns external attributes of the file.

Returns:

  • (Fixnum)

    external attributes of the file



156
157
158
# File 'lib/zip_tricks/file_reader.rb', line 156

def external_attrs
  @external_attrs
end

#filenameString

Returns the filename.

Returns:

  • (String)

    the filename



147
148
149
# File 'lib/zip_tricks/file_reader.rb', line 147

def filename
  @filename
end

#gp_flagsFixnum

Returns bit-packed general purpose flags.

Returns:

  • (Fixnum)

    bit-packed general purpose flags



126
127
128
# File 'lib/zip_tricks/file_reader.rb', line 126

def gp_flags
  @gp_flags
end

#internal_attrsFixnum

Returns internal attributes of the file.

Returns:

  • (Fixnum)

    internal attributes of the file



153
154
155
# File 'lib/zip_tricks/file_reader.rb', line 153

def internal_attrs
  @internal_attrs
end

#local_file_header_offsetFixnum

Returns at what offset the local file header starts in your original IO object.

Returns:

  • (Fixnum)

    at what offset the local file header starts in your original IO object



160
161
162
# File 'lib/zip_tricks/file_reader.rb', line 160

def local_file_header_offset
  @local_file_header_offset
end

#made_byFixnum

Returns bit-packed version signature of the program that made the archive.

Returns:

  • (Fixnum)

    bit-packed version signature of the program that made the archive



120
121
122
# File 'lib/zip_tricks/file_reader.rb', line 120

def made_by
  @made_by
end

#storage_modeFixnum

Returns Storage mode (0 for stored, 8 for deflate).

Returns:

  • (Fixnum)

    Storage mode (0 for stored, 8 for deflate)



129
130
131
# File 'lib/zip_tricks/file_reader.rb', line 129

def storage_mode
  @storage_mode
end

#uncompressed_sizeFixnum

Returns size of the file once uncompressed.

Returns:

  • (Fixnum)

    size of the file once uncompressed



144
145
146
# File 'lib/zip_tricks/file_reader.rb', line 144

def uncompressed_size
  @uncompressed_size
end

#version_needed_to_extractFixnum

Returns ZIP version support needed to extract this file.

Returns:

  • (Fixnum)

    ZIP version support needed to extract this file



123
124
125
# File 'lib/zip_tricks/file_reader.rb', line 123

def version_needed_to_extract
  @version_needed_to_extract
end

Instance Method Details

#extractor_from(from_io) ⇒ #extract(n_bytes), #eof?

Returns a reader for the actual compressed data of the entry.

reader = entry.reader(source_file) outfile << reader.extract(512 * 1024) until reader.eof?

Returns:

  • (#extract(n_bytes), #eof?)

    the reader for the data



175
176
177
178
179
180
181
182
183
184
185
# File 'lib/zip_tricks/file_reader.rb', line 175

def extractor_from(from_io)
  from_io.seek(compressed_data_offset, IO::SEEK_SET)
  case storage_mode
  when 8
    InflatingReader.new(from_io, compressed_size)
  when 0
    StoredReader.new(from_io, compressed_size)
  else
    raise "Unsupported storage mode for reading (#{storage_mode})"
  end
end