lib/bencodr.rb in bencodr-1.0.1 vs lib/bencodr.rb in bencodr-1.1.0
- old
+ new
@@ -17,22 +17,21 @@
# BEncode.decode("6:string") #=> "string"
#
# @param [::String] string the bencoded string to decode
# @return [::String, ::Integer, ::Hash, ::Array] the decoded object
def decode(string)
- scanner = StringScanner.new(string)
- Parser.parse_object(scanner) or raise BEncodeError, "Invalid bencoding"
+ string.bdecode
end
# This method decodes a bencoded file.
#
# 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(file)
- decode(File.open(file, 'rb') {|f| f.read})
+ def decode_file(name)
+ decode(File.open(name, 'rb') {|file| file.read})
end
# This method encodes a bencoded object.
#
# BEncode.encode("string") #=> "6:string"
@@ -47,10 +46,10 @@
#
# 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(file, object)
- File.open(file, 'wb') {|f| f.write encode(object)}
+ def encode_file(name, object)
+ File.open(name, 'wb') {|file| file.write encode(object)}
end
end
end
\ No newline at end of file