lib/vfs/storages/local.rb in vfs-0.3.11 vs lib/vfs/storages/local.rb in vfs-0.3.12

- old
+ new

@@ -2,10 +2,20 @@ require 'tempfile' module Vfs module Storages class Local + class Writer + def initialize out + @out = out + end + + def write data + @out.write data + end + end + module LocalVfsHelper DEFAULT_BUFFER = 1000 * 1024 attr_writer :buffer def buffer @@ -49,12 +59,11 @@ def write_file path, append, &block # TODO2 Performance lost, extra call to check file existence raise "can't write, entry #{path} already exist!" if !append and ::File.exist?(path) option = append ? 'a' : 'w' - ::File.open path, option do |os| - writer = -> buff {os.write buff} - block.call writer + ::File.open path, option do |out| + block.call Writer.new(out) end end def delete_file path ::File.delete path \ No newline at end of file