zip_tricks 4.7.3 → 4.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +12 -6
- data/lib/zip_tricks/stream_crc32.rb +14 -1
- data/lib/zip_tricks/version.rb +1 -1
- data/lib/zip_tricks/write_buffer.rb +2 -0
- data/zip_tricks.gemspec +1 -0
- metadata +16 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d1119a96243d5da6b423a2a3c992efc6fbb580fa
         | 
| 4 | 
            +
              data.tar.gz: 63a1d0b2c93e5b231568e83efb60220862c07b7e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 89c7300a0c3af8ceb0408d2c4315fc62e4abf5fecc53ca93219bf9ce30c146d9cc8bca193d35908f1d24516bc1298c12332850ff0352dd561ed67a56a6fe7211
         | 
| 7 | 
            +
              data.tar.gz: 20cdfca60a6ac3cc5beaa57bf74dba06bd09ef18931931ddead388de68e6316650e4aad14fe96b7838b415babaafe9f8aa72ca5a9ccd547eb535f3e6f27901f4
         | 
    
        data/.rubocop.yml
    CHANGED
    
    
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/LICENSE.txt
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -30,7 +30,7 @@ The easiest is to use the Rails' built-in streaming feature: | |
| 30 30 | 
             
            class ZipsController < ActionController::Base
         | 
| 31 31 | 
             
              include ActionController::Live # required for streaming
         | 
| 32 32 | 
             
              include ZipTricks::RailsStreaming
         | 
| 33 | 
            -
             | 
| 33 | 
            +
             | 
| 34 34 | 
             
              def download
         | 
| 35 35 | 
             
                zip_tricks_stream do |zip|
         | 
| 36 36 | 
             
                  zip.write_deflated_file('report1.csv') do |sink|
         | 
| @@ -122,10 +122,10 @@ ZipTricks::Streamer.open(io) do | zip | | |
| 122 122 | 
             
              # raw_file is written "as is" (STORED mode).
         | 
| 123 123 | 
             
              # Write the local file header first..
         | 
| 124 124 | 
             
              zip.add_stored_entry(filename: "first-file.bin", size: raw_file.size, crc32: raw_file_crc32)
         | 
| 125 | 
            -
             | 
| 125 | 
            +
             | 
| 126 126 | 
             
              # then send the actual file contents bypassing the Streamer interface
         | 
| 127 127 | 
             
              io.sendfile(my_temp_file)
         | 
| 128 | 
            -
             | 
| 128 | 
            +
             | 
| 129 129 | 
             
              # ...and then adjust the ZIP offsets within the Streamer
         | 
| 130 130 | 
             
              zip.simulate_write(my_temp_file.size)
         | 
| 131 131 | 
             
            end
         | 
| @@ -143,7 +143,7 @@ It is slightly more convenient for the purpose than using the raw Zlib library f | |
| 143 143 |  | 
| 144 144 | 
             
            ```ruby
         | 
| 145 145 | 
             
            crc = ZipTricks::StreamCRC32.new
         | 
| 146 | 
            -
            crc <<  | 
| 146 | 
            +
            crc << next_chunk_of_data
         | 
| 147 147 | 
             
            ...
         | 
| 148 148 |  | 
| 149 149 | 
             
            crc.to_i # Returns the actual CRC32 value computed so far
         | 
| @@ -152,6 +152,12 @@ crc.to_i # Returns the actual CRC32 value computed so far | |
| 152 152 | 
             
            crc.append(precomputed_crc32, size_of_the_blob_computed_from)
         | 
| 153 153 | 
             
            ```
         | 
| 154 154 |  | 
| 155 | 
            +
            You can also compute the CRC32 for an entire IO object if it responds to `#eof?`:
         | 
| 156 | 
            +
             | 
| 157 | 
            +
            ```ruby
         | 
| 158 | 
            +
            crc = ZipTricks::StreamCRC32.from_io(file) # Returns an Integer
         | 
| 159 | 
            +
            ```
         | 
| 160 | 
            +
             | 
| 155 161 | 
             
            ## Reading ZIP files
         | 
| 156 162 |  | 
| 157 163 | 
             
            The library contains a reader module, play with it to see what is possible. It is not a complete ZIP reader
         | 
| @@ -160,7 +166,7 @@ as such it performs it's function quite well. Please beware of the security impl | |
| 160 166 | 
             
            that have not been formally verified (ours hasn't been).
         | 
| 161 167 |  | 
| 162 168 | 
             
            ## Contributing to zip_tricks
         | 
| 163 | 
            -
             | 
| 169 | 
            +
             | 
| 164 170 | 
             
            * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
         | 
| 165 171 | 
             
            * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
         | 
| 166 172 | 
             
            * Fork the project.
         | 
| @@ -172,4 +178,4 @@ that have not been formally verified (ours hasn't been). | |
| 172 178 |  | 
| 173 179 | 
             
            ## Copyright
         | 
| 174 180 |  | 
| 175 | 
            -
            Copyright (c)  | 
| 181 | 
            +
            Copyright (c) 2019 WeTransfer. See LICENSE.txt for further details.
         | 
| @@ -2,13 +2,26 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            # A simple stateful class for keeping track of a CRC32 value through multiple writes
         | 
| 4 4 | 
             
            class ZipTricks::StreamCRC32
         | 
| 5 | 
            +
              STRINGS_HAVE_CAPACITY_SUPPORT = begin
         | 
| 6 | 
            +
                String.new('', capacity: 1)
         | 
| 7 | 
            +
                true
         | 
| 8 | 
            +
              rescue ArgumentError
         | 
| 9 | 
            +
                false
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
              CRC_BUF_SIZE = 1024 * 512
         | 
| 12 | 
            +
              private_constant :STRINGS_HAVE_CAPACITY_SUPPORT, :CRC_BUF_SIZE
         | 
| 13 | 
            +
             | 
| 5 14 | 
             
              # Compute a CRC32 value from an IO object. The object should respond to `read` and `eof?`
         | 
| 6 15 | 
             
              #
         | 
| 7 16 | 
             
              # @param io[IO] the IO to read the data from
         | 
| 8 17 | 
             
              # @return [Fixnum] the computed CRC32 value
         | 
| 9 18 | 
             
              def self.from_io(io)
         | 
| 19 | 
            +
                # If we can specify the string capacity upfront we will not have to resize
         | 
| 20 | 
            +
                # the string during operation. This saves time but is only available on
         | 
| 21 | 
            +
                # recent Ruby 2.x versions.
         | 
| 22 | 
            +
                blob = STRINGS_HAVE_CAPACITY_SUPPORT ? String.new('', capacity: CRC_BUF_SIZE) : String.new('')
         | 
| 10 23 | 
             
                crc = new
         | 
| 11 | 
            -
                crc << io.read( | 
| 24 | 
            +
                crc << io.read(CRC_BUF_SIZE, blob) until io.eof?
         | 
| 12 25 | 
             
                crc.to_i
         | 
| 13 26 | 
             
              end
         | 
| 14 27 |  | 
    
        data/lib/zip_tricks/version.rb
    CHANGED
    
    
    
        data/zip_tricks.gemspec
    CHANGED
    
    | @@ -40,6 +40,7 @@ Gem::Specification.new do |spec| | |
| 40 40 | 
             
              spec.add_development_dependency 'complexity_assert'
         | 
| 41 41 | 
             
              spec.add_development_dependency 'coderay'
         | 
| 42 42 | 
             
              spec.add_development_dependency 'benchmark-ips'
         | 
| 43 | 
            +
              spec.add_development_dependency 'allocation_stats', '~> 0.1.5'
         | 
| 43 44 | 
             
              spec.add_development_dependency 'yard', '~> 0.9'
         | 
| 44 45 | 
             
              spec.add_development_dependency 'wetransfer_style', '0.6.0'
         | 
| 45 46 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: zip_tricks
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 4.7. | 
| 4 | 
            +
              version: 4.7.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Julik Tarkhanov
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2019- | 
| 11 | 
            +
            date: 2019-06-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -150,6 +150,20 @@ dependencies: | |
| 150 150 | 
             
                - - ">="
         | 
| 151 151 | 
             
                  - !ruby/object:Gem::Version
         | 
| 152 152 | 
             
                    version: '0'
         | 
| 153 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 154 | 
            +
              name: allocation_stats
         | 
| 155 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 156 | 
            +
                requirements:
         | 
| 157 | 
            +
                - - "~>"
         | 
| 158 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 159 | 
            +
                    version: 0.1.5
         | 
| 160 | 
            +
              type: :development
         | 
| 161 | 
            +
              prerelease: false
         | 
| 162 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 163 | 
            +
                requirements:
         | 
| 164 | 
            +
                - - "~>"
         | 
| 165 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 166 | 
            +
                    version: 0.1.5
         | 
| 153 167 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 154 168 | 
             
              name: yard
         | 
| 155 169 | 
             
              requirement: !ruby/object:Gem::Requirement
         |