lib/json-write-stream.rb in json-write-stream-1.0.0 vs lib/json-write-stream.rb in json-write-stream-1.0.1
- old
+ new
@@ -3,21 +3,26 @@
require 'json'
require 'json-write-stream/yielding'
require 'json-write-stream/stateful'
class JsonWriteStream
+ DEFAULT_ENCODING = Encoding::UTF_8
+
class << self
- def from_stream(stream)
+ def from_stream(stream, encoding = DEFAULT_ENCODING)
+ stream.set_encoding(encoding)
+
if block_given?
yield writer = YieldingWriter.new(stream)
writer.close
else
StatefulWriter.new(stream)
end
end
- def open(file)
+ def open(file, encoding = DEFAULT_ENCODING)
handle = File.open(file, 'w')
+ handle.set_encoding(encoding)
if block_given?
yield writer = YieldingWriter.new(handle)
writer.close
else