diff options
Diffstat (limited to 'lib/ffi-xattr/windows_lib.rb')
-rw-r--r-- | lib/ffi-xattr/windows_lib.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/ffi-xattr/windows_lib.rb b/lib/ffi-xattr/windows_lib.rb new file mode 100644 index 0000000..d4199cc --- /dev/null +++ b/lib/ffi-xattr/windows_lib.rb @@ -0,0 +1,45 @@ +# encoding: utf-8 +require 'ffi-xattr' + +class Xattr # :nodoc: all + module Lib + class << self + + def list(path, no_follow) + lines = `dir /r "#{path}"`.split("\n") + + xattrs = [] + lines.each { |line| + if line =~ /\:\$DATA$/ + size = line.split(' ')[0].gsub(/[^0-9]/,'').to_i + + if size > 0 + xattrs << line.split(':')[1] + end + end + } + xattrs + end + + def get(path, no_follow, key) + fp = "#{path}:#{key}" + if File.exists?(fp) + File.binread(fp) + else + raise "No such key. #{key.inspect} #{path.inspect}" + end + end + + def set(path, no_follow, key, value) + File.open("#{path}:#{key}",'wb') { |io| io << value } + end + + def remove(path, no_follow, key) + # done this way because Windows have no function to remove Alternate Data Stream + # quickest way is to set the value to 0 byte length instead of trying to create another file then apply the attributes, especially when dealing with a big file + self.set(path, false, key, '') + end + end + + end +end |