class Ld::File
Attributes
exist[RW]
mode[RW]
name[RW]
path[RW]
size[RW]
stat[RW]
suffix[RW]
type[RW]
Public Class Methods
base64(path)
click to toggle source
编码base64
# File lib/ld/file/file.rb, line 21 def self.base64 path Base64.encode64(File.open(path, 'rb').read) end
current()
click to toggle source
new(path)
click to toggle source
# File lib/ld/file/file.rb, line 7 def initialize path @path = path[0] == '/' ? path : "#{Dir.pwd}/#{path}" @name = File.basename @path read_attrs end
open(path)
click to toggle source
test()
click to toggle source
test:
# File lib/ld/file/file.rb, line 206 def self.test sdf{100.times{Ld::File.new('app').search_regexp //}} end
write(path, arr)
click to toggle source
# File lib/ld/file/file.rb, line 201 def self.write path, arr File.open(path) end
write_image_by_base64_and_path(base64, path)
click to toggle source
解码base64,并写入图片
# File lib/ld/file/file.rb, line 26 def self.write_image_by_base64_and_path base64, path File.open(path,'wb').write(Base64.decode64 base64) end
Public Instance Methods
children()
click to toggle source
delete()
click to toggle source
details()
click to toggle source
# File lib/ld/file/file.rb, line 217 def details Ld::Dir.new(@path).details end
dir!()
click to toggle source
# File lib/ld/file/file.rb, line 78 def dir! raise "这不是一个目录,而是一个#{type}:#{path}" if type != 'directory' end
dir?()
click to toggle source
dirs()
click to toggle source
exist!()
click to toggle source
# File lib/ld/file/file.rb, line 64 def exist! raise "不存在的 #{path}" if !@exist end
file!()
click to toggle source
# File lib/ld/file/file.rb, line 82 def file! raise "这不是一个文件,而是一个#{type}:#{path}" if type != 'file' end
file?()
click to toggle source
files()
click to toggle source
find(name)
click to toggle source
is_exclude?(name)
click to toggle source
# File lib/ld/file/file.rb, line 55 def is_exclude? name @@exclude.include? name end
iter_search(name, results)
click to toggle source
# File lib/ld/file/file.rb, line 122 def iter_search name, results children.each do |file| if file.name == name results << file end if file.dir? file.iter_search name, results end end end
iter_search_regexp(regexp, results)
click to toggle source
# File lib/ld/file/file.rb, line 133 def iter_search_regexp regexp, results children.each do |file| if file.name.match(regexp) results << file end if file.dir? file.iter_search_regexp regexp, results end end end
lines()
click to toggle source
look()
click to toggle source
# File lib/ld/file/file.rb, line 45 def look puts lines end
ls()
click to toggle source
parent()
click to toggle source
read_attrs()
click to toggle source
# File lib/ld/file/file.rb, line 30 def read_attrs @suffix = @name.split('.').last @suffix = @suffix == @name ? nil : @suffix if File.exist? @path @exist = true @type = File.ftype path @stat = File.stat path @size = @stat.size @mode = @stat.mode else @exist = false @type = 'not found' end end
rename(new_name)
click to toggle source
sdf(&block)
click to toggle source
# File lib/ld/file/file.rb, line 210 def sdf &block t1 = Time.new block.call t2 = Time.new puts t2 - t1 end
search(name, type = :all)
click to toggle source
search_regexp(regexp, type = :all)
click to toggle source