|
1 | | -function Sink(fullpath::AbstractString; |
| 1 | +function Sink(fullpath::Union{AbstractString, IO}; |
2 | 2 | delim::Char=',', |
3 | 3 | quotechar::Char='"', |
4 | 4 | escapechar::Char='\\', |
@@ -33,7 +33,7 @@ Data.streamtypes(::Type{CSV.Sink}) = [Data.Field] |
33 | 33 | Data.weakrefstrings(::Type{CSV.Sink}) = true |
34 | 34 |
|
35 | 35 | # Constructors |
36 | | -function Sink(sch::Data.Schema, T, append, file::AbstractString; reference::Vector{UInt8}=UInt8[], kwargs...) |
| 36 | +function Sink(sch::Data.Schema, T, append, file::Union{AbstractString, IO}; reference::Vector{UInt8}=UInt8[], kwargs...) |
37 | 37 | sink = Sink(file; append=append, colnames=Data.header(sch), kwargs...) |
38 | 38 | return sink |
39 | 39 | end |
|
70 | 70 | function Data.close!(sink::CSV.Sink) |
71 | 71 | io = isa(sink.fullpath, AbstractString) ? open(sink.fullpath, sink.append ? "a" : "w") : sink.fullpath |
72 | 72 | Base.write(io, take!(sink.io)) |
73 | | - applicable(close, io) && close(io) |
| 73 | + isa(sink.fullpath, AbstractString) && close(io) |
74 | 74 | return sink |
75 | 75 | end |
76 | 76 |
|
@@ -130,11 +130,11 @@ CSV.write("sqlite_table.csv", sqlite_source) |
130 | 130 | """ |
131 | 131 | function write end |
132 | 132 |
|
133 | | -function write(file::AbstractString, ::Type{T}, args...; append::Bool=false, transforms::Dict=Dict{Int,Function}(), kwargs...) where {T} |
| 133 | +function write(file::Union{AbstractString, IO}, ::Type{T}, args...; append::Bool=false, transforms::Dict=Dict{Int,Function}(), kwargs...) where {T} |
134 | 134 | sink = Data.stream!(T(args...), CSV.Sink, file; append=append, transforms=transforms, kwargs...) |
135 | 135 | return Data.close!(sink) |
136 | 136 | end |
137 | | -function write(file::AbstractString, source; append::Bool=false, transforms::Dict=Dict{Int,Function}(), kwargs...) |
| 137 | +function write(file::Union{AbstractString, IO}, source; append::Bool=false, transforms::Dict=Dict{Int,Function}(), kwargs...) |
138 | 138 | sink = Data.stream!(source, CSV.Sink, file; append=append, transforms=transforms, kwargs...) |
139 | 139 | return Data.close!(sink) |
140 | 140 | end |
|
0 commit comments