Fix file decode #3

merged 3 commits into from Mar 23, 2012

2 participants


Fix ArgumentError: invalid byte sequence in UTF-8 when decoding real files in ruby-1.9.2p312:

# or
file ='bencode.txt', 'rb')

Add necessary tests.
Remove force_encoding('UTF-8') from File#bdecode.
Fix minor error in readme file.
Also had update gem dependencies.

quaternion added some commits Mar 23, 2012
quaternion fix "invalid byte sequence in UTF-8" error when decoding files
add necessary tests
remove force_encoding from File#bdecode
quaternion fix error in readme 112a011
quaternion update gem dependencies 3dbe519
@blatyo blatyo commented on the diff Mar 23, 2012
- before :each do
- @file = File.join(@path, 'test.bencodr')
- @object = "string"
- File.bencode(@file, @object)
+ let(:file) {'test.bencodr') }
+ let(:object) { "string" }
+ describe ".bencode" do
+ it "should encode object to file" do
+ File.bencode(file, object)
+ file.rewind
+ == "6:string"
+ end
blatyo Mar 23, 2012 Owner

Cool trick. Didn't know about Tempfile.


This removes the only dependency I had on any ruby 1.9 features which is cool. I'll have to get this project setup with travis, to make sure this doesn't break for older rubies.

@blatyo blatyo merged commit 99f3568 into blatyo:master Mar 23, 2012

+1 setup with travis.


There are some 1.8 things that are preventing me from pushing the gem. One is:

Failure/Error: File.bencode(file, object)
63     TypeError:
64       can't convert Tempfile into String
65     # ./lib/bencodr/io.rb:7:in `initialize'
66     # ./lib/bencodr/io.rb:7:in `open'
67     # ./lib/bencodr/io.rb:7:in `bencode'
68     # ./spec/bencodr/io_spec.rb:15

Most of the others are just odd differences between rubies where I'll probably have specs for different versions of ruby.


Good, 1.9.2 and 1.9.3 work correctly. I'll try to switch to 1.8.7 and find out the cause of errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment