Method: ZipKit::ZipWriter#write_local_file_header
- Defined in:
- lib/zip_kit/zip_writer.rb
#write_local_file_header(io:, filename:, compressed_size:, uncompressed_size:, crc32:, gp_flags:, mtime:, storage_mode:) ⇒ void
This method returns an undefined value.
Writes the local file header, that precedes the actual file data.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/zip_kit/zip_writer.rb', line 74 def write_local_file_header(io:, filename:, compressed_size:, uncompressed_size:, crc32:, gp_flags:, mtime:, storage_mode:) requires_zip64 = compressed_size > FOUR_BYTE_MAX_UINT || uncompressed_size > FOUR_BYTE_MAX_UINT # local file header signature 4 bytes (0x04034b50) io << [0x04034b50].pack(C_UINT4) # version needed to extract 2 bytes io << if requires_zip64 [VERSION_NEEDED_TO_EXTRACT_ZIP64].pack(C_UINT2) else [VERSION_NEEDED_TO_EXTRACT].pack(C_UINT2) end # general purpose bit flag 2 bytes io << [gp_flags].pack(C_UINT2) # compression method 2 bytes io << [storage_mode].pack(C_UINT2) # last mod file time 2 bytes io << [to_binary_dos_time(mtime)].pack(C_UINT2) # last mod file date 2 bytes io << [to_binary_dos_date(mtime)].pack(C_UINT2) # crc-32 4 bytes io << [crc32].pack(C_UINT4) if requires_zip64 # compressed size 4 bytes io << [FOUR_BYTE_MAX_UINT].pack(C_UINT4) # uncompressed size 4 bytes io << [FOUR_BYTE_MAX_UINT].pack(C_UINT4) else # compressed size 4 bytes io << [compressed_size].pack(C_UINT4) # uncompressed size 4 bytes io << [uncompressed_size].pack(C_UINT4) end # Filename should not be longer than 0xFFFF otherwise this wont fit here # file name length 2 bytes io << [filename.bytesize].pack(C_UINT2) extra_fields = StringIO.new # Interesting tidbit: # https://social.technet.microsoft.com/Forums/windows/en-US/6a60399f-2879-4859-b7ab-6ddd08a70948 # TL;DR of it is: Windows 7 Explorer _will_ open Zip64 entries. However, it desires to have the # Zip64 extra field as _the first_ extra field. if requires_zip64 extra_fields << zip_64_extra_for_local_file_header(compressed_size: compressed_size, uncompressed_size: uncompressed_size) end extra_fields << (mtime) # extra field length 2 bytes io << [extra_fields.size].pack(C_UINT2) # file name (variable size) io << filename # Contents of the extra fields (variable size) io << extra_fields.string end |