gossamer/file

Types

pub type Fields {
  Fields(
    name: String,
    last_modified: Int,
    size: Int,
    type_: String,
  )
}

Constructors

  • Fields(
      name: String,
      last_modified: Int,
      size: Int,
      type_: String,
    )

A Blob with a filename and last-modified timestamp. Commonly obtained from file inputs or drag-and-drop.

See File on MDN.

pub type File
pub type FileOption {
  Type(String)
  LastModified(Int)
}

Constructors

  • Type(String)
  • LastModified(Int)

Values

pub fn array_buffer(
  of file: File,
) -> promise.Promise(
  Result(array_buffer.ArrayBuffer, js_error.JsError),
)

Reads the file’s contents as an ArrayBuffer. Returns an error if the file cannot be read.

pub fn bytes(
  of file: File,
) -> promise.Promise(
  Result(uint8_array.Uint8Array, js_error.JsError),
)

Reads the file’s contents as a Uint8Array. Returns an error if the file cannot be read.

pub fn from_blob(blob: blob.Blob, named name: String) -> File
pub fn from_blob_with(
  blob: blob.Blob,
  named name: String,
  with options: List(FileOption),
) -> File
pub fn from_strings(
  parts: List(String),
  named name: String,
) -> File
pub fn from_strings_with(
  parts: List(String),
  named name: String,
  with options: List(FileOption),
) -> File
pub fn last_modified(of file: File) -> Int
pub fn name(of file: File) -> String
pub fn size(of file: File) -> Int
pub fn slice(
  file: File,
  from start: Int,
  to end: Int,
) -> blob.Blob
pub fn slice_with_type(
  file: File,
  from start: Int,
  to end: Int,
  content_type content_type: String,
) -> blob.Blob
pub fn text(
  of file: File,
) -> promise.Promise(Result(String, js_error.JsError))

Reads the file’s contents as a UTF-8 string. Returns an error if the file cannot be read.

pub fn to_blob(file: File) -> blob.Blob
pub fn to_fields(file: File) -> Fields
pub fn type_(of file: File) -> String
Search Document