Class: Browser::FileList::File

Inherits:
Object
  • Object
show all
Defined in:
lib/browser/file_list.rb

Overview

An individual item in a FileList

Defined Under Namespace

Classes: FileReader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ File

Returns a new instance of File.

Parameters:

  • native (JS)

    the native File object to wrap



50
51
52
53
# File 'lib/browser/file_list.rb', line 50

def initialize native
  @native = native
  @data = nil
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



47
48
49
# File 'lib/browser/file_list.rb', line 47

def data
  @data
end

Instance Method Details

#last_modifiedTime

Returns the timestamp of the file.

Returns:

  • (Time)

    the timestamp of the file



71
72
73
# File 'lib/browser/file_list.rb', line 71

def last_modified
  `#@native.lastModifiedDate`
end

#nameString

Returns the filename.

Returns:

  • (String)

    the filename



56
57
58
# File 'lib/browser/file_list.rb', line 56

def name
  `#@native.name`
end

#readPromise

Read the file from disk into memory

Returns:

  • (Promise)

    a promise that resolves when finished loading and rejects if an error occurs while loading.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/browser/file_list.rb', line 79

def read
  promise = Promise.new
  reader = FileReader.new
  reader.on :load do
    result = reader.result

    @data = result
    promise.resolve result
  end

  reader.on :error do
    promise.reject reader.result
  end

  reader.read_as_binary_string self

  promise
end

#sizeInteger

Returns the size of this file on disk.

Returns:

  • (Integer)

    the size of this file on disk



61
62
63
# File 'lib/browser/file_list.rb', line 61

def size
  `#@native.size`
end

#to_nJS.HTMLElement

Convert to the native object

Returns:

  • (JS.HTMLElement)

    the underlying native element



101
102
103
# File 'lib/browser/file_list.rb', line 101

def to_n
  @native
end

#typeString

Returns the MIME type of the file, detected by the browser.

Returns:

  • (String)

    the MIME type of the file, detected by the browser



66
67
68
# File 'lib/browser/file_list.rb', line 66

def type
  `#@native.type`
end