lib/rbbt/persist.rb in rbbt-util-4.3.0 vs lib/rbbt/persist.rb in rbbt-util-4.4.0

- old
+ new

@@ -1,7 +1,5 @@ -require 'digest/md5' - require 'rbbt/util/misc' require 'rbbt/util/open' require 'rbbt/persist/tsv' require 'set' @@ -89,10 +87,15 @@ TSV.setup(Marshal.load(Open.open(path))) when :fwt FixWidthTable.get(path) when :string, :text Open.read(path) + when :binary + f = File.open(path, 'rb') + res = f.read + f.close + res when :array res = Open.read(path).split("\n", -1) res.pop res when :marshal @@ -126,15 +129,20 @@ Open.write(path, content.to_s) when :annotations Open.write(path, Annotated.tsv(content, :all).to_s) when :string, :text Open.write(path, content) + when :binary + f = File.open(path, 'wb') + f.puts content + f.close + content when :array - if content.any? - Open.write(path, content * "\n" + "\n") - else + if content.empty? Open.write(path, "") + else + Open.write(path, content * "\n" + "\n") end when :marshal_tsv Open.write(path, Marshal.dump(content.dup)) when :marshal Open.write(path, Marshal.dump(content)) @@ -183,10 +191,10 @@ nil when (keys.length == 1 and keys.first == subkey + 'EMPTY') [] when (keys.length == 1 and keys.first =~ /:SINGLE$/) key = keys.first - values = repo.write_and_close do + values = repo.read_and_close do repo[key] end Annotated.load_tsv_values(key, values, "literal", "annotation_types", "JSON") when keys.any? repo.read_and_close do