lib/tori/backend/filesystem.rb in tori-0.6.6 vs lib/tori/backend/filesystem.rb in tori-0.7.0
- old
+ new
@@ -43,15 +43,32 @@
def exist?(filename)
::File.exist? path(filename)
end
alias exists? exist?
- def read(filename, **args)
- ::File.read(path(filename), { mode: 'rb' }.merge(args))
+ def read(filename, *args)
+ if args.last.kind_of?(Hash)
+ opt = args.pop
+ else
+ opt = {}
+ end
+ open(filename, {mode: 'rb'}.merge(opt)) do |f|
+ f.read(*args)
+ end
end
def open(filename, *rest, &block)
::File.open(path(filename), *rest, &block)
+ end
+
+ def copy_to(filename, tori_file, **opts)
+ FileUtils.mkdir_p tori_file.path.dirname
+
+ ::File.open(path(filename)) do |from|
+ ::File.open(tori_file.path, 'w+') do |to|
+ IO.copy_stream(from, to)
+ end
+ end
end
def path(filename)
@root.join filename.to_s
end