Class: Curl::SafeDownloadOutput
- Inherits:
-
Object
- Object
- Curl::SafeDownloadOutput
- Defined in:
- lib/curl/download.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #close(success = false) ⇒ Object
-
#initialize(path, overwrite: false) ⇒ SafeDownloadOutput
constructor
A new instance of SafeDownloadOutput.
- #write(data) ⇒ Object
Constructor Details
#initialize(path, overwrite: false) ⇒ SafeDownloadOutput
Returns a new instance of SafeDownloadOutput.
104 105 106 107 108 109 110 111 112 |
# File 'lib/curl/download.rb', line 104 def initialize(path, overwrite: false) @path = File.(path.to_s) @overwrite = overwrite raise DownloadTargetExistsError, @path if !@overwrite && File.exist?(@path) @tmp = Tempfile.new(['.curb-download-', '.tmp'], File.dirname(@path)) @tmp.binmode @closed = false end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
114 115 116 |
# File 'lib/curl/download.rb', line 114 def path @path end |
Instance Method Details
#<<(data) ⇒ Object
120 121 122 |
# File 'lib/curl/download.rb', line 120 def <<(data) write(data) end |
#close(success = false) ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/curl/download.rb', line 124 def close(success = false) return if @closed @tmp.flush unless @tmp.closed? @tmp.close unless @tmp.closed? install_tmp_file if success ensure @tmp.close! if @tmp @closed = true end |
#write(data) ⇒ Object
116 117 118 |
# File 'lib/curl/download.rb', line 116 def write(data) @tmp.write(data) end |