Index: lib/pstore.rb =================================================================== --- lib/pstore.rb (revision 33263) +++ lib/pstore.rb (working copy) @@ -363,7 +363,7 @@ def open_and_lock_file(filename, read_only) if read_only begin - file = File.new(filename, RD_ACCESS) + file = File.new(filename, RD_ACCESS, external_encoding: Encoding::BINARY) begin file.flock(File::LOCK_SH) return file @@ -375,7 +375,7 @@ return nil end else - file = File.new(filename, RDWR_ACCESS) + file = File.new(filename, RDWR_ACCESS, external_encoding: Encoding::BINARY) file.flock(File::LOCK_EX) return file end Index: test/test_pstore.rb =================================================================== --- test/test_pstore.rb (revision 33263) +++ test/test_pstore.rb (working copy) @@ -110,4 +110,13 @@ pstore.transaction { pstore.transaction { } } end end + + # Test that PStore's file operations do not blow up when default encodings are set + def test_pstore_files_are_accessed_as_binary_files + Encoding.default_internal = 'utf-8' + Encoding.default_external = 'utf-8' + (1..1000).each do |i| + @pstore.transaction { @pstore["Key#{i}"] = "value #{i}" } + end + end end