From 77c9f264e09d33f89220cf7c8e5c474ad4979509 Mon Sep 17 00:00:00 2001 From: coezbek Date: Wed, 29 Jul 2020 13:53:11 +0200 Subject: [PATCH] Use binary file read/write for marshalling I have used diskcached (with joy) for many years but only now stumbled upon an issue where a serialized hash can't be read again. Looking into the code I found that diskcached doesn't use binary file mode. I believe this is an error and bound to cause issues with newlines (\r\n vs. \r vs. \n) at least under Windows. Could you merge my pull request? --- lib/diskcached.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/diskcached.rb b/lib/diskcached.rb index 9cd2867..1adbbf0 100644 --- a/lib/diskcached.rb +++ b/lib/diskcached.rb @@ -149,7 +149,7 @@ def cache_file key private # creates the actual cache file def write_cache_file key, content - f = File.open( cache_file(key), "w+" ) + f = File.open( cache_file(key), "wb+" ) f.flock(File::LOCK_EX) f.write( content ) f.close @@ -158,7 +158,7 @@ def write_cache_file key, content # reads the actual cache file def read_cache_file key - f = File.open( cache_file(key), "r" ) + f = File.open( cache_file(key), "rb" ) f.flock(File::LOCK_SH) out = f.read f.close