FAQ
Hi !

httprs adds Seek to http.Response.Body by doing range requests. A
HttpReadSeeker implements io.ReadCloser and io.Seeker.

Usage :

resp, err := http.Get(url)
rs := httprs.NewHttpReadSeeker(resp)
defer rs.Close()
io.ReadFull(rs, buf) // reads the first bytes from the response body
rs.Seek(1024, 0) // moves the position, but does no range request
io.ReadFull(rs, buf) // does a range request and reads from the response
body

https://github.com/jfbus/httprs

Enjoy !

Jean-François

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Vasiliy Tolstov at Apr 1, 2015 at 9:44 am

    2015-04-01 12:12 GMT+03:00 Jean-François Bustarret <jfbubus@gmail.com>:
    Hi !

    httprs adds Seek to http.Response.Body by doing range requests. A
    HttpReadSeeker implements io.ReadCloser and io.Seeker.

    Usage :

    resp, err := http.Get(url)
    rs := httprs.NewHttpReadSeeker(resp)
    defer rs.Close()
    io.ReadFull(rs, buf) // reads the first bytes from the response body
    rs.Seek(1024, 0) // moves the position, but does no range request
    io.ReadFull(rs, buf) // does a range request and reads from the response
    body

    https://github.com/jfbus/httprs

    Thanks! Sometimes ago i'm write something like this. But to use in
    real world can you create readahead? Becasue if you read file at size
    4Gb with buffer 4K, you need to create tons of syscalls.

    --
    Vasiliy Tolstov,
    e-mail: v.tolstov@selfip.ru
    jabber: vase@selfip.ru

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jean-François Bustarret at Apr 1, 2015 at 10:07 am
    Le mercredi 1 avril 2015 11:45:08 UTC+2, Vasiliy Tolstov a écrit :
    Thanks! Sometimes ago i'm write something like this. But to use in
    real world can you create readahead? Becasue if you read file at size
    4Gb with buffer 4K, you need to create tons of syscalls.
    httprs is just a wrapper above res.Body, it does nothing more, nothing less
    (AFAIK) than resp.Body...

    I can't a way of doing read-ahead unless the std lib supports it.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Tommi Virtanen at Apr 2, 2015 at 11:07 pm

    On Wednesday, April 1, 2015 at 2:12:59 AM UTC-7, Jean-François Bustarret wrote:


    Hi !

    httprs adds Seek to http.Response.Body by doing range requests. A
    HttpReadSeeker implements io.ReadCloser and io.Seeker.
    You should use If-Range to make sure it's still the same content.

    There's also https://github.com/DHowett/ranger

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Vasiliy Tolstov at Apr 3, 2015 at 6:31 am

    2015-04-03 2:07 GMT+03:00 Tommi Virtanen <tommi.virtanen@gmail.com>:
    You should use If-Range to make sure it's still the same content.

    There's also https://github.com/DHowett/ranger

    Very interesting.!

    --
    Vasiliy Tolstov,
    e-mail: v.tolstov@selfip.ru
    jabber: vase@selfip.ru

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jean-François Bustarret at Apr 3, 2015 at 9:17 am
    Le vendredi 3 avril 2015 01:07:50 UTC+2, Tommi Virtanen a écrit :
    On Wednesday, April 1, 2015 at 2:12:59 AM UTC-7, Jean-François Bustarret
    wrote:

    Hi !

    httprs adds Seek to http.Response.Body by doing range requests. A
    HttpReadSeeker implements io.ReadCloser and io.Seeker.
    You should use If-Range to make sure it's still the same content.
    There's also https://github.com/DHowett/ranger
    <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2FDHowett%2Franger&sa=D&sntz=1&usg=AFQjCNHWH4jGX-ERtGKsdUdLn4BFBYhxqw>
    Using If-Range implies you have a cache of previously download content.
    Ranger has an in-memory cache of all downloaded chunks.

    My use case is http video streaming (big files, long connections,
    concurrent accesses => very high memory usage), with mainly forward seeking
    (=> low cache hit ratio). Not a good candidate for an in-memory cache. If I
    had to implement a cache, it would not be memory based, and it would be
    shared between readers.

    I also wanted to let the user do the initial request (in case he would
    require authentication, cookies, or whatever). Ranger builds all http
    requests himself, auth and cookies are not possible.

    Difference use case, different solution. Just pick the best solution for
    your use case.

    Jean-François

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Tommi Virtanen at Apr 10, 2015 at 4:16 pm

    On Friday, April 3, 2015 at 2:17:07 AM UTC-7, Jean-François Bustarret wrote:
    You should use If-Range to make sure it's still the same content.
    Using If-Range implies you have a cache of previously download content.
    Ranger has an in-memory cache of all downloaded chunks.
    No, If-Range just helps make sure all the ranges you fetch are part of the
    same revision of content.

    For example, a browser playing an uncached mp4 will use If-Range to make
    sure the metadata it fetches from the end of the file matches the video
    it's buffering.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jean-François Bustarret at Apr 12, 2015 at 5:44 pm
    Le vendredi 10 avril 2015 18:16:05 UTC+2, Tommi Virtanen a écrit :
    On Friday, April 3, 2015 at 2:17:07 AM UTC-7, Jean-François Bustarret
    wrote:
    You should use If-Range to make sure it's still the same content.
    Using If-Range implies you have a cache of previously download content.
    Ranger has an in-memory cache of all downloaded chunks.
    No, If-Range just helps make sure all the ranges you fetch are part of the
    same revision of content.

    For example, a browser playing an uncached mp4 will use If-Range to make
    sure the metadata it fetches from the end of the file matches the video
    it's buffering.
    You are right. I'll see how it can be implemented.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 1, '15 at 9:13a
activeApr 12, '15 at 5:44p
posts8
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase