Skip to content

Commit

Permalink
Implement binread (mimic ASCII-8BIT encoding) (#1824)
Browse files Browse the repository at this point in the history
* Implement binread (mimic ASCII-8BIT encoding)

* Use toString method
  • Loading branch information
ggrossetie authored and iliabylich committed May 12, 2018
1 parent 34f89df commit a7124ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/nodejs/io.rb
Expand Up @@ -36,7 +36,7 @@ def self.read(path)
end

def self.binread(path)
`return executeIOAction(function(){return __fs__.readFileSync(#{path}).toString('binary')})`
`return executeIOAction(function(){return __fs__.readFileSync(#{path}).toString('utf-8')})`
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/nodejs/test_io.rb
Expand Up @@ -15,4 +15,10 @@ def test_binread_noexistent_should_raise_io_error
IO.binread('tmp/nonexistent')
end
end

def test_binread_encoding
File.write('tmp/foo', 'Le français c\'est compliqué :)\n')
assert_equal("Le fran\xC3\xA7ais c'est compliqu\xC3\xA9 :)\\n", IO.binread('tmp/foo'))
assert_equal("Le français c'est compliqué :)\\n", IO.binread('tmp/foo'))
end
end

0 comments on commit a7124ee

Please sign in to comment.