summaryrefslogtreecommitdiff
path: root/lib/csv.rb
diff options
context:
space:
mode:
authornahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-06 14:03:58 +0000
committernahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-10-06 14:03:58 +0000
commit11d2edffe68fdd52d3a8a6bad26f774c9dd27dfa (patch)
tree145b354c037072de0d6608943f03fadaaa033ab4 /lib/csv.rb
parent26d111540e3aac50a9bfe2b363ea2d98a5339f7c (diff)
* lib/csv.rb (IOReader, BasicWriter): call binmode when a given IO
respond_to?(:binmode). record separator was wrong when you gave text mode IO to Reader.parse and Writer.generate. * test/csv/test_csv.rb: add tests for above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/csv.rb')
-rw-r--r--lib/csv.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/csv.rb b/lib/csv.rb
index ee686db0cf..10c86f6417 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -463,6 +463,7 @@ public
#
def initialize(io, col_sep = ?,, row_sep = nil)
@io = io
+ @io.binmode if @io.respond_to?(:binmode)
@col_sep = col_sep
@row_sep = row_sep
@dev = CSV::IOBuf.new(@io)
@@ -551,8 +552,8 @@ public
# Create instance. To add CSV data to generate CSV string, see
# CSV::Writer#<< or CSV::Writer#add_row.
#
- def Writer.create(str_or_readable, col_sep = ?,, row_sep = nil)
- BasicWriter.new(str_or_readable, col_sep, row_sep)
+ def Writer.create(str_or_writable, col_sep = ?,, row_sep = nil)
+ BasicWriter.new(str_or_writable, col_sep, row_sep)
end
# SYNOPSIS
@@ -675,6 +676,7 @@ public
@col_sep = col_sep
@row_sep = row_sep
@dev = str_or_writable
+ @dev.binmode if @dev.respond_to?(:binmode)
@close_on_terminate = false
end
@@ -1036,7 +1038,7 @@ private
when :DT_COLSEP
out_dev << col_sep.chr
when :DT_ROWSEP
- out_dev << (row_sep || "\r\n")
+ out_dev << (row_sep ? row_sep.chr : "\r\n")
end
end
end