Class: Fsinv::FileDescription

Inherits:
BaseDescription show all
Includes:
Fsinv
Defined in:
lib/fsinv/filedescription.rb

Constant Summary

Constants included from Fsinv

BYTES_IN_GB, BYTES_IN_GiB, BYTES_IN_KB, BYTES_IN_KiB, BYTES_IN_MB, BYTES_IN_MiB, BYTES_IN_TB, BYTES_IN_TiB, IGNORE_FILES, PSEUDO_FILES, VERSION

Instance Attribute Summary collapse

Attributes inherited from BaseDescription

#bytes, #ctime, #fshugo_tags, #mtime, #osx_tags, #path

Instance Method Summary collapse

Methods included from Fsinv

filestructure_to_db, filestructure_to_xml, inventory_to_json, inventory_to_xml, inventory_to_yaml, parse, pretty_IEC_bytes, pretty_SI_bytes, sanitize_string

Methods inherited from BaseDescription

#fshugo_tag_ids, #osx_tag_ids

Constructor Details

#initialize(path, reduced_scan = false) ⇒ FileDescription

Returns a new instance of FileDescription.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fsinv/filedescription.rb', line 12

def initialize(path, reduced_scan = false)

  super(path,reduced_scan)
  
  begin
    @bytes = File.size(@path) 
  rescue 
    puts "error: exception getting size for file #{path}" if Fsinv.options[:verbose]
    @bytes = 0
  end

  unless reduced_scan # don't do this if we only want to know file sizes (for pseudofiles, .git folders, etc)
    @mimetype = get_mime_id
    @magicdescr = get_magic_descr_ids
    @crc32 = calc_crc32
    @md5 = calc_md5
  end
end

Instance Attribute Details

#crc32Object

Returns the value of attribute crc32.



10
11
12
# File 'lib/fsinv/filedescription.rb', line 10

def crc32
  @crc32
end

#magicdescrObject

Returns the value of attribute magicdescr.



10
11
12
# File 'lib/fsinv/filedescription.rb', line 10

def magicdescr
  @magicdescr
end

#md5Object

Returns the value of attribute md5.



10
11
12
# File 'lib/fsinv/filedescription.rb', line 10

def md5
  @md5
end

#mimetypeObject

Returns the value of attribute mimetype.



10
11
12
# File 'lib/fsinv/filedescription.rb', line 10

def mimetype
  @mimetype
end

Instance Method Details

#as_json(options = { }) ⇒ Object

to_hash



41
42
43
# File 'lib/fsinv/filedescription.rb', line 41

def as_json(options = { })
  return to_hash
end

#marshal_dumpObject



49
50
51
52
53
# File 'lib/fsinv/filedescription.rb', line 49

def marshal_dump
  h = self.to_json
  h.delete("type")
  return h
end

#marshal_load(data) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fsinv/filedescription.rb', line 55

def marshal_load(data)
  self.path = data['path']
  self.bytes = data['bytes']
  self.ctime = data['ctime'] if data['ctime'].exists?
  self.mtime = data['mtime'] if data['mtime'].exists?
  self.mimetype = data['mimetype'] if data['mimetype'].exists?
  self.magicdescr = data['magicdescr'] if data['magicdescr'].exists?
  self.crc32 = data["crc32"] if data['crc32'].exists?
  self.md5 = data["md5"] if data['md5'].exists?
  self.osx_tags = data['osx_tags'] if data['osx_tags'].exists?
  self.fshugo_tags = data['fshugo_tags'] if data['fshugo_tags'].exists?
end

#to_hashObject

initialize



31
32
33
34
35
36
37
38
39
# File 'lib/fsinv/filedescription.rb', line 31

def to_hash
  h = { "type" => "file" }
  h = h.merge(super.to_hash)
  h["mimetype"] = @mimetype unless @mimetype.nil?
  h["magicdescr"] = @magicdescr unless @magicdescr.nil?
  h["crc32"] = @crc32 unless @crc32.nil?
  h["md5"] = @md5 unless @md5.nil?
  return h
end

#to_json(*a) ⇒ Object



45
46
47
# File 'lib/fsinv/filedescription.rb', line 45

def to_json(*a)
  return as_json.to_json(*a )
end