Coder Social home page Coder Social logo

Comments (4)

seanmonstar avatar seanmonstar commented on May 5, 2024 1

Ohhh OK, so this isn't to try to just tweak some content as it streams by, you'd like to map the path to a static file, but after that, create a whole different Response using the contents of that file...

In your case, you'd want to buffer the full contents in memory, but people probably wouldn't want that with bigger files. Perhaps this could be handled by adding a new Filter to warp::fs, which doesn't try to reply with the file, but instead provides you with the tokio_fs::File so you can do whatever you want with it?

from warp.

seanmonstar avatar seanmonstar commented on May 5, 2024

Can you say more about what you hope to do it? The exact type of streaming bodies hasn't been exposed yet, as I want to be able to add automatic compression support, and currently worry that might require changes, which would need a breaking change.

That said, mapping the streaming body chunks does seem useful. Possibly using with, or something?

let route = warp::fs::dir("static")
    .with(warp::reply::with::map_body(|buf: impl Buf| {
        // return a new `impl Buf` instead
    }));

from warp.

ZoeyR avatar ZoeyR commented on May 5, 2024

I was thinking something along the lines of: I have a blog that uses a template file for a page, based on what the users request I retrieve a text file (via warp::fs::dir) and then use the string of that file to render the template with the post's contents.

from warp.

ZoeyR avatar ZoeyR commented on May 5, 2024

That sounds like it would work perfectly!

from warp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.