Sha256: 480298c43ebca4a968c2a7b3038243ea0f7aae9ac764facc72f3be53a308eb91
Contents?: true
Size: 725 Bytes
Versions: 3
Compression:
Stored size: 725 Bytes
Contents
# encoding: UTF-8 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, 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, encoding = DEFAULT_ENCODING) handle = File.open(file, 'w') handle.set_encoding(encoding) if block_given? yield writer = YieldingWriter.new(handle) writer.close else StatefulWriter.new(handle) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
json-write-stream-1.1.0 | lib/json-write-stream.rb |
json-write-stream-1.0.2 | lib/json-write-stream.rb |
json-write-stream-1.0.1 | lib/json-write-stream.rb |