Documentation navigation

Published API · 0.1.0-rc.1

foldkit · file

Published foldkit API declarations for file.

./file

@wsagency/wseffect-foldkit · MIT · source · MIT license · WS-AGENCY-NOTICE · THIRD-PARTY-NOTICES

This entry point is published in @wsagency/wseffect-foldkit@0.1.0-rc.1. Import it from the package subpath shown below; the signatures and documentation are read from the installed package declarations.

import * as Wseffect from '@wsagency/wseffect-foldkit/file'

Exported declarations

File

A file selected by the user. Direct alias for the browser's native `File` type — opaque by convention (Foldkit never constructs files itself, only receives them from `File.select`, `File.selectMultiple`, or from `OnFileChange`/`OnDropFiles` event attributes).

export type File = globalThis.File;

File

Schema that accepts any value that is an instance of the DOM `File` class. Use in Model fields that hold user-selected files: ```ts attachedResume: Schema.Option(File.File) ```

File: Schema.Schema<File>

FileReadError

Error raised when a `FileReader` operation fails.

export declare class FileReadError extends FileReadError_base<{
    readonly reason: string;
}> {
}

mimeType

The file's MIME type (e.g. `"application/pdf"`), or empty string if the browser cannot determine one.

mimeType: (file: File) => string

name

The file's name including extension, as reported by the browser.

name: (file: File) => string

readAsArrayBuffer

Reads the file's contents as raw binary data. Mirrors Elm's `File.toBytes`. Use this when you need the full binary payload (e.g. to upload, hash, or parse a custom file format). For images you usually want `readAsDataUrl` instead.

readAsArrayBuffer: (file: File) => Effect.Effect<ArrayBuffer, FileReadError>

readAsDataUrl

Reads the file's contents as a base64-encoded data URL. Useful for rendering image previews without uploading the file first. Mirrors Elm's `File.toUrl`.

readAsDataUrl: (file: File) => Effect.Effect<string, FileReadError>

readAsText

Reads the file's contents as a UTF-8 string. Mirrors Elm's `File.toString`. Fails with a `FileReadError` if the browser's `FileReader` encounters an error (e.g. the file was deleted while reading). Handle failures with `Effect.catch` to convert them into a failure Message.

readAsText: (file: File) => Effect.Effect<string, FileReadError>

select

Opens the native file picker allowing a single file to be selected. Resolves with `Option.some(file)` if the user picked one, or `Option.none()` if they cancelled. Mirrors Elm's `File.Select.file`. The `accept` argument is a list of MIME types or file extensions that restrict what the picker shows. Pass an empty array to allow any file.

select: (accept: ReadonlyArray<string>) => Effect.Effect<Option.Option<File>>

selectMultiple

Opens the native file picker allowing multiple files to be selected at once. Resolves with the array of selected files, or an empty array if the user cancelled. Mirrors Elm's `File.Select.files`.

selectMultiple: (accept: ReadonlyArray<string>) => Effect.Effect<ReadonlyArray<File>>

size

The file's size in bytes.

size: (file: File) => number