Giter VIP home page Giter VIP logo

Comments (9)

fabi321 avatar fabi321 commented on August 23, 2024

This could also be implemented as an async stream of information about the download.

from rustube.

DzenanJupic avatar DzenanJupic commented on August 23, 2024

@fabi321 sounds reasonable.

The best place for such a hook would probably be in src/stream/mod.rs:261

async fn write_stream_to_file(mut stream: impl tokio_stream::Stream<Item=reqwest::Result<bytes::Bytes>> + Unpin, file: &mut File) -> Result<()> {
        while let Some(chunk) = stream.next().await {
            file
                .write_all(&chunk?)
                .await?;
        }
        Ok(())
    }

This function handles the response stream and writes incoming byte-chunks to the target file.

Implementing it similar to pytube, by having a dedicated struct for download arguments is probably the best idea. This would allow adding arguments in the future without making a breaking change.

I won't have time to implement this within the next few days, so you're welcome to make PR. Otherwise, I will implement it within the next few weeks.

from rustube.

DzenanJupic avatar DzenanJupic commented on August 23, 2024

This could also be implemented as an async stream of information about the download.

That also sounds like an interesting option, especially, since it allows the other side to stop listening when it's done with its task.

tokios channel could be used for that. It returns a Receiver that can be turned into a Stream using ReceiverStream.

The main question here would be if the download should stop when the Receiver is dropped - kind of like a kill switch - or if such errors should be ignored.

from rustube.

fabi321 avatar fabi321 commented on August 23, 2024

I tried to hide this behind a feature since it needs tokio/sync, but the resulting code either has a lot of duplication or looks ugly. Would you mind if my solution does not require a feature to be activated?

from rustube.

fabi321 avatar fabi321 commented on August 23, 2024

Nvm, I just added yet more fields to the Stream struct.

from rustube.

DzenanJupic avatar DzenanJupic commented on August 23, 2024

@fabi321 thank you for the effort.

It's no problem if it's activated without a feature. The feature system is far from perfect/finished and I will eventually redo it from scratch.

from rustube.

fabi321 avatar fabi321 commented on August 23, 2024

I now opened #9 as a first go to. It's using a feature now

from rustube.

fabi321 avatar fabi321 commented on August 23, 2024

It's completely lacking an actual executor, but provides my first thoughts on the topic

from rustube.

fabi321 avatar fabi321 commented on August 23, 2024

Fixed as #9 is merged

from rustube.

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.