$30 off During Our Annual Pro Sale. View Details »

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?

Peter Hellberg

November 24, 2011
Tweet

More Decks by Peter Hellberg

Other Decks in Programming

Transcript

  1. PINCH
    Some crazy
    HTTP ZIP Magic

    View Slide

  2. @peterhellberg

    View Slide

  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)

    View Slide

  4. Retrieve a ile rom
    inside a ZIP ile,
    over the network!
    Pretty sweet, eh?

    View Slide

  5. require 'pinch'
    url = 'http://peterhellberg.github.com/pinch/test.zip'
    data = Pinch.get(url, 'data.json')
    # Do something with the data
    How?

    View Slide

  6. Now, let’s go
    back in⏰

    View Slide

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

    View Slide

  8. FILE ENTRY 1
    FILE ENTRY 2
    CENTRAL DIRECTORY
    END OF CENTRAL DIRECTORY
    Signature 0x06054b50

    ZIP File Format

    View Slide

  9. Pinch does NOT
    understand the
    ZIP File Format

    View Slide

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

    View Slide

  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

    View Slide

  12. String#unpack
    Zlib::In late
    Array#pack

    View Slide

  13. gem install pinch

    View Slide

  14. github.com/peterhellberg/pinch

    View Slide

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

    View Slide