module Browser # An individual item in a FileList class File attr_reader :data # @param native [JS] the native File object to wrap def initialize native @native = native @data = nil end # @return [String] the filename def name `#@native.name` end # @return [Integer] the size of this file on disk def size `#@native.size` end # @return [String] the MIME type of the file, detected by the browser def type `#@native.type` end # @return [Time] the timestamp of the file def last_modified `#@native.lastModifiedDate` end # Read the file from disk into memory # # @return [Promise] a promise that resolves when finished loading and # rejects if an error occurs while loading. 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 # Convert to the native object # # @return [JS.HTMLElement] the underlying native element def to_n @native end end end