@@ -158,29 +158,22 @@ class << self
158
158
# the graph or repository to dump
159
159
# @param [IO, File, String] io
160
160
# the output stream or file to write to
161
- # @param [Encoding, String, Symbol] encoding
162
- # the encoding to use on the output stream.
163
- # Defaults to the format associated with `content_encoding`.
164
161
# @param [Hash{Symbol => Object}] options
165
162
# passed to {RDF::Writer#initialize} or {RDF::Writer.buffer}
166
163
# @return [void]
167
- def self . dump ( data , io = nil , encoding : nil , **options )
168
- if io . is_a? ( String )
169
- io = File . open ( io , 'w' )
170
- elsif io . respond_to? ( :external_encoding ) && io . external_encoding
171
- encoding ||= io . external_encoding
172
- end
173
- io . set_encoding ( encoding ) if io . respond_to? ( :set_encoding ) && encoding
164
+ def self . dump ( data , io = nil , **options )
165
+ io = File . open ( io , 'w' ) if io . is_a? ( String )
174
166
method = data . respond_to? ( :each_statement ) ? :each_statement : :each
175
167
if io
176
- new ( io , encoding : encoding , **options ) do |writer |
168
+ new ( io , **options ) do |writer |
169
+ io . set_encoding ( writer . encoding ) if io . respond_to? ( :set_encoding )
177
170
data . send ( method ) do |statement |
178
171
writer << statement
179
172
end
180
173
writer . flush
181
174
end
182
175
else
183
- buffer ( encoding : encoding , **options ) do |writer |
176
+ buffer ( **options ) do |writer |
184
177
data . send ( method ) do |statement |
185
178
writer << statement
186
179
end
@@ -191,23 +184,21 @@ def self.dump(data, io = nil, encoding: nil, **options)
191
184
##
192
185
# Buffers output into a string buffer.
193
186
#
194
- # @param [Encoding, String, Symbol] encoding
195
- # the encoding to use on the output stream.
196
- # Defaults to the format associated with `content_encoding`.
197
187
# @param [Hash{Symbol => Object}] options
198
188
# passed to {RDF::Writer#initialize}
199
189
# @yield [writer]
200
190
# @yieldparam [RDF::Writer] writer
201
191
# @yieldreturn [void]
202
192
# @return [String]
203
193
# @raise [ArgumentError] if no block is provided
204
- def self . buffer ( *args , encoding : nil , **options , &block )
205
- encoding ||= Encoding ::UTF_8 if RUBY_PLATFORM == "java"
194
+ def self . buffer ( *args , **options , &block )
206
195
raise ArgumentError , "block expected" unless block_given?
207
196
208
197
StringIO . open do |buffer |
209
- buffer . set_encoding ( encoding ) if encoding
210
- self . new ( buffer , *args , encoding : encoding , **options ) { |writer | block . call ( writer ) }
198
+ self . new ( buffer , *args , **options ) do |writer |
199
+ buffer . set_encoding ( writer . encoding )
200
+ block . call ( writer )
201
+ end
211
202
buffer . string
212
203
end
213
204
end
@@ -216,19 +207,18 @@ def self.buffer(*args, encoding: nil, **options, &block)
216
207
# Writes output to the given `filename`.
217
208
#
218
209
# @param [String, #to_s] filename
219
- # @param [Encoding, String, Symbol] encoding
220
- # the encoding to use on the output stream.
221
- # Defaults to the format associated with `content_encoding`.
222
210
# @param [Symbol] format (nil)
223
211
# @param [Hash{Symbol => Object}] options
224
212
# any additional options (see {RDF::Writer#initialize} and {RDF::Format.for})
225
213
# @return [RDF::Writer]
226
- def self . open ( filename , encoding : nil , format : nil , **options , &block )
214
+ def self . open ( filename , format : nil , **options , &block )
227
215
File . open ( filename , 'wb' ) do |file |
228
- file . set_encoding ( encoding ) if encoding
229
216
format_options = options . dup
230
217
format_options [ :file_name ] ||= filename
231
- self . for ( format || format_options ) . new ( file , encoding : encoding , **options , &block )
218
+ self . for ( format || format_options ) . new ( file , **options ) do |writer |
219
+ file . set_encoding ( writer . encoding )
220
+ block . call ( writer )
221
+ end
232
222
end
233
223
end
234
224
0 commit comments