Class: Browser::FileList::File
Overview
An individual item in a FileList
Defined Under Namespace
Classes: FileReader
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#initialize(native) ⇒ File
constructor
A new instance of File.
-
#last_modified ⇒ Time
The timestamp of the file.
-
#name ⇒ String
The filename.
-
#read ⇒ Promise
Read the file from disk into memory.
-
#size ⇒ Integer
The size of this file on disk.
-
#to_n ⇒ JS.HTMLElement
Convert to the native object.
-
#type ⇒ String
The MIME type of the file, detected by the browser.
Constructor Details
#initialize(native) ⇒ File
Returns a new instance of File.
50 51 52 53 |
# File 'lib/browser/file_list.rb', line 50 def initialize native @native = native @data = nil end |
Instance Attribute Details
#data ⇒ Object (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_modified ⇒ Time
Returns the timestamp of the file.
71 72 73 |
# File 'lib/browser/file_list.rb', line 71 def last_modified `#@native.lastModifiedDate` end |
#name ⇒ String
Returns the filename.
56 57 58 |
# File 'lib/browser/file_list.rb', line 56 def name `#@native.name` end |
#read ⇒ Promise
Read the file from disk into memory
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 |
#size ⇒ Integer
Returns the size of this file on disk.
61 62 63 |
# File 'lib/browser/file_list.rb', line 61 def size `#@native.size` end |
#to_n ⇒ JS.HTMLElement
Convert to the native object
101 102 103 |
# File 'lib/browser/file_list.rb', line 101 def to_n @native end |
#type ⇒ String
Returns 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 |