Pinch - Some crazy HTTP ZIP Magic

Pinch - Some crazy HTTP ZIP Magic

Retrieve a file from inside a ZIP file, over the network!

Pretty sweet, eh?

8d7c0c3b32899cccf8d0abb080a18c20?s=128

Peter Hellberg

November 24, 2011
Tweet

Transcript

  1. PINCH Some crazy HTTP ZIP Magic

  2. @peterhellberg

  3. I’m a Senior Systems Architect at Athega (where I build

    stuff in Ruby) ⃔ I’m also the owner o Code7 Interactive (where I build stuff in Ruby) ⃕
  4. Retrieve a ile rom inside a ZIP ile, over the

    network! Pretty sweet, eh?
  5. require 'pinch' url = 'http://peterhellberg.github.com/pinch/test.zip' data = Pinch.get(url, 'data.json') #

    Do something with the data How?
  6. Now, let’s go back in⏰

  7. ’89 APPNOTE.TXT http://PKWARE.com/documents/casestudies/APPNOTE.TXT

  8. FILE ENTRY 1 <local ile header> <data> FILE ENTRY 2

    <local ile header> <data> CENTRAL DIRECTORY <offset to local file headers> END OF CENTRAL DIRECTORY Signature 0x06054b50 <offset to start of central directory> ZIP File Format
  9. Pinch does NOT understand the ZIP File Format

  10. HTTP/1.1 14.16 Content-Range ❤ || ☠

  11. 1 HEAD Total ile size 2 GET Last 4096 bytes

    (End of Central Directory) 3 GET Central Directory start → Central Directory start + size 4 GET File offset → File offset + (compressed) size HTTP Requests
  12. String#unpack Zlib::In late Array#pack

  13. gem install pinch

  14. github.com/peterhellberg/pinch

  15. @peterhellberg peterhellberg.info git.io/peterhellberg