GithubHelp home page GithubHelp logo

save the file about down HOT 4 CLOSED

janko avatar janko commented on May 11, 2024
save the file

from down.

Comments (4)

janko avatar janko commented on May 11, 2024

@derrickcope It doesn't currently have that functionality, because it was never needed in Shrine (the project it originated from), but I always thought it should have it. At the moment the file is saved into a temporary location, but it doesn't yet have a way to specify permanent user-defined location.

I'll try to implement this later today or tomorrow, but for now you can use this:

tempfile = Down.download("...")
tempfile.close
FileUtils.mv tempfile.path, "/path/to/destination"

from down.

derrickcope avatar derrickcope commented on May 11, 2024

That would be great! I managed to save it another way.

tempfile = Down.open(uri, rewindable: false)
File.open(filename, "wb") do |file|
file.write(tempfile.read)
tempfile.close
end 

The only problem is it saves it in memory and then outputs to the file. How would I stream it directly to the saved file?
thanks

from down.

janko avatar janko commented on May 11, 2024

@derrickcope IO.copy_stream is a wonderful method:

io = Down.open(uri, rewindable: false)
File.open(filename, "wb") do |file|
  IO.copy_stream(io, file)
  io.close
end 

or even shorter:

io = Down.open(uri, rewindable: false)
IO.copy_stream(io, filename)
io.close

from down.

derrickcope avatar derrickcope commented on May 11, 2024

Thanks

from down.

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.