lib/bencodr.rb in bencodr-1.1.0 vs lib/bencodr.rb in bencodr-1.2.0
- old
+ new
@@ -5,10 +5,11 @@
require path + "/string"
require path + "/integer"
require path + "/list"
require path + "/dictionary"
require path + "/parser"
+require path + "/io"
module BEncodr
class BEncodeError < StandardError; end
class << self
@@ -27,11 +28,11 @@
# BEncode.decode_file("simple.torrent") #=> "d8:announce32:http://www..."
#
# @param [::String] file the file to decode
# @return [::String, ::Integer, ::Hash, ::Array] the decoded object
def decode_file(name)
- decode(File.open(name, 'rb') {|file| file.read})
+ File.bdecode name
end
# This method encodes a bencoded object.
#
# BEncode.encode("string") #=> "6:string"
@@ -47,9 +48,9 @@
# BEncode.encode("string") #=> "6:string"
#
# @param [::String] file the file to write the bencoded object to
# @param [#bencodr] object the object to encode
def encode_file(name, object)
- File.open(name, 'wb') {|file| file.write encode(object)}
+ File.bencode name, object
end
end
end
\ No newline at end of file