diff --git a/lib/stackprof/report.rb b/lib/stackprof/report.rb index e282f668..26478802 100644 --- a/lib/stackprof/report.rb +++ b/lib/stackprof/report.rb @@ -10,10 +10,14 @@ class Report class << self def from_file(file) - if (content = IO.binread(file)).start_with?(MARSHAL_SIGNATURE) - new(Marshal.load(content)) - else - from_json(JSON.parse(content)) + File.open(file, 'rb') do |f| + signature_bytes = f.read(2) + f.rewind + if signature_bytes == MARSHAL_SIGNATURE + new(Marshal.load(f)) + else + from_json(JSON.parse(f.read)) + end end end