Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CSV"
uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
authors = ["Jacob Quinn <quinn.jacobd@gmail.com>"]
version = "0.10.15"
version = "0.10.16"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Expand Down
11 changes: 6 additions & 5 deletions src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function Base.iterate(r::RowWriter)
colnames = isempty(r.header) ? Tables.columnnames(row) : r.header
pos = 1
if r.options.bom
pos = writebom(r.buf, pos, length(r.buf))
pos = writebom(r.buf, pos, length(r.buf), DummyIO())
end
cols = length(colnames)
!r.writeheader && return iterate(r, (state, cols))
Expand Down Expand Up @@ -215,7 +215,7 @@ function write(sch::Tables.Schema, rows, file, opts;
with(file, append, compress) do io
Base.@_inline_meta
if !append && opts.bom
pos = writebom(buf, pos, len)
pos = writebom(buf, pos, len, io)
end
if header === true || (header isa Vector && !append)
pos = writenames(buf, pos, len, io, colnames, cols, opts)
Expand Down Expand Up @@ -244,7 +244,7 @@ function write(::Nothing, rows, file, opts;
if state === nothing
if header isa Vector && !isempty(header)
with(file, append, compress) do io
!append && opts.bom && (pos = writebom(buf, pos, len) )
!append && opts.bom && (pos = writebom(buf, pos, len, io) )
pos = writenames(buf, pos, len, io, header, length(header), opts)
Base.write(io, resize!(buf, pos - 1))
end
Expand All @@ -257,7 +257,7 @@ function write(::Nothing, rows, file, opts;
cols = length(names)
with(file, append, compress) do io
if !append && opts.bom
pos = writebom(buf, pos, len)
pos = writebom(buf, pos, len, io)
end
if header === true || (header isa Vector && !append)
pos = writenames(buf, pos, len, io, names, cols, opts)
Expand Down Expand Up @@ -306,6 +306,7 @@ end

macro check(n)
esc(quote
@assert @isdefined(io) "internal error: `io` not defined in scope of `@check` macrocall"
$n > length(buf) && buffertoosmall(pos + $n - 1, length(buf))
if (pos + $n - 1) > len
Base.write(io, view(buf, 1:(pos - 1)))
Expand All @@ -314,7 +315,7 @@ macro check(n)
end)
end

function writebom(buf, pos, len)
function writebom(buf, pos, len, io)
@check 3
@inbounds buf[pos] = 0xEF
@inbounds buf[pos+1] = 0xBB
Expand Down
4 changes: 4 additions & 0 deletions test/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,8 @@ Base.string(x::AF) = string(x.f)
str = CSV.writerow(row; delim='\t')
@test str == "1\t2.3\they\t2022-05-04\n"

# CSV.writebom
# https://github.com/JuliaData/CSV.jl/pull/1179
@test CSV.writebom(UInt8[1,2,3], 2, 1, IOBuffer()) isa Int

end # @testset "CSV.write"
Loading