Skip to main content

QLocalStorageEngine

@quik/storage


@quik/storage / QLocalStorageEngine

Class: QLocalStorageEngine

Defined in: storage/src/engine/QLocalStorageEngine.ts:24

Extends

Constructors

Constructor

new QLocalStorageEngine(): QLocalStorageEngine

Defined in: storage/src/engine/QLocalStorageEngine.ts:30

Returns

QLocalStorageEngine

Overrides

QStorageEngineBase.constructor

Properties

_basePath

protected _basePath: string

Defined in: storage/src/engine/QLocalStorageEngine.ts:28

Base filesystem path for local storage.


_name

protected _name: string

Defined in: storage/src/engine/QStorageEngineBase.ts:22

Storage engine name.

Inherited from

QStorageEngineBase._name


_type

protected _type: QStorageEngineType = QStorageEngineType.LOCAL

Defined in: storage/src/engine/QStorageEngineBase.ts:34

Storage engine type.

Inherited from

QStorageEngineBase._type

Accessors

logger

Get Signature

get protected logger(): IQLogger

Defined in: core/src/QObject.ts:15

The logger getter for the object.

Returns

IQLogger

Inherited from

QStorageEngineBase.logger


name

Get Signature

get name(): string

Defined in: storage/src/engine/QStorageEngineBase.ts:27

Storage engine name.

Returns

string

Inherited from

QStorageEngineBase.name


type

Get Signature

get type(): QStorageEngineType

Defined in: storage/src/engine/QStorageEngineBase.ts:39

Storage engine type.

Returns

QStorageEngineType

Inherited from

QStorageEngineBase.type

Methods

buildSignedUrl()

protected buildSignedUrl(purpose, token): string

Defined in: storage/src/engine/QLocalStorageEngine.ts:331

Build the full signed URL for a local storage token.

Parameters

purpose

"upload" | "download"

Whether this URL grants a download or an upload.

token

string

Signed token produced by LocalSignature.sign.

Returns

string


copy()

copy(sourcePath, destinationPath): Promise<void>

Defined in: storage/src/engine/QLocalStorageEngine.ts:166

Copy a local file within the storage root.

Parameters

sourcePath

string

Source storage path.

destinationPath

string

Destination storage path.

Returns

Promise<void>

Throws

StorageFileNotFoundError when the source file is missing.

Overrides

QStorageEngineBase.copy


copyTo()

copyTo(file, targetEngine, targetPath): Promise<void>

Defined in: storage/src/engine/QLocalStorageEngine.ts:185

Copy a file to another storage engine.

Parameters

file

QStorageFile

Source storage file.

targetEngine

QStorageEngineBase

Target storage engine.

targetPath

string

Destination path in the target engine.

Returns

Promise<void>

Throws

StorageFileNotFoundError when the source file is missing.

Overrides

QStorageEngineBase.copyTo


create()

create(file, path, fill?): Promise<QStorageFile>

Defined in: storage/src/engine/QStorageEngineBase.ts:86

Save a file and return a refreshed metadata record.

Parameters

file

QStorageFile

Storage file to save.

path

string

Storage path where the file should be stored.

fill?

boolean = false

Whether to load contents into memory.

Returns

Promise<QStorageFile>

Inherited from

QStorageEngineBase.create


detectEncodingFromBuffer()

protected detectEncodingFromBuffer(buffer): string

Defined in: storage/src/engine/QLocalStorageEngine.ts:348

Detect text encoding from file byte order marks.

Parameters

buffer

Buffer

Buffer containing the file header.

Returns

string


detectEncodingFromPath()

protected detectEncodingFromPath(path): Promise<string>

Defined in: storage/src/engine/QLocalStorageEngine.ts:376

Detect encoding for a file on disk.

Parameters

path

string

File path to inspect.

Returns

Promise<string>


endSpan()

protected endSpan(span): void

Defined in: core/src/QObject.ts:35

End a span returned by startSpan.

Parameters

span

TelemetrySpan

The span to end.

Returns

void

Inherited from

QStorageEngineBase.endSpan


get()

get(path, fill?): Promise<QStorageFile>

Defined in: storage/src/engine/QLocalStorageEngine.ts:41

Resolve a file and optionally load contents.

Parameters

path

string

Storage path for the file.

fill?

boolean = false

Whether to load contents into memory.

Returns

Promise<QStorageFile>

Overrides

QStorageEngineBase.get


getFileStat()

protected getFileStat(path): Promise<Stats>

Defined in: storage/src/engine/QLocalStorageEngine.ts:401

Returns file stats for a path if it exists and is a file.

Parameters

path

string

Filesystem path to check.

Returns

Promise<Stats>


getPath()

protected getPath(...pathItems): string

Defined in: storage/src/engine/QLocalStorageEngine.ts:392

Parameters

pathItems

...string[]

Returns

string


getSignedDownloadURL()

getSignedDownloadURL(filePath, expiresIn?): Promise<string>

Defined in: storage/src/engine/QLocalStorageEngine.ts:320

Generate a signed, time-limited download URL for a local storage path.

Parameters

filePath

string

Storage path to download.

expiresIn?

number

Expiration time in seconds. Defaults to storage.local.signed.download.

Returns

Promise<string>

Throws

StorageLocalSigningSecretMissingError when no signing secret is configured.

Overrides

QStorageEngineBase.getSignedDownloadURL


getSignedUploadURL()

getSignedUploadURL(filePath, expiresIn?): Promise<string>

Defined in: storage/src/engine/QLocalStorageEngine.ts:308

Generate a signed, time-limited upload URL for a local storage path.

Parameters

filePath

string

Storage path the upload should be written to.

expiresIn?

number

Expiration time in seconds. Defaults to storage.local.signed.upload.

Returns

Promise<string>

Throws

StorageLocalSigningSecretMissingError when no signing secret is configured.

Overrides

QStorageEngineBase.getSignedUploadURL


getUrl()

getUrl(file): Promise<string>

Defined in: storage/src/engine/QLocalStorageEngine.ts:283

Resolve a public URL for a local file.

Parameters

file

QStorageFile

Storage file to resolve a URL for.

Returns

Promise<string>

Overrides

QStorageEngineBase.getUrl


importFromPath()

importFromPath(sourcePath, destinationPath, removeSource?): Promise<void>

Defined in: storage/src/engine/QLocalStorageEngine.ts:255

Import a file from disk into local storage.

Parameters

sourcePath

string

OS path to the source file.

destinationPath

string

Storage path to save the file to.

removeSource?

boolean = false

Whether to delete the source file after copy.

Returns

Promise<void>

Throws

StorageFileNotFoundError when the source file is missing.

Overrides

QStorageEngineBase.importFromPath


init()

protected init(): void

Defined in: storage/src/engine/QLocalStorageEngine.ts:413

Returns

void

Overrides

QStorageEngineBase.init


move()

move(sourcePath, destinationPath): Promise<void>

Defined in: storage/src/engine/QLocalStorageEngine.ts:148

Move a local file within the storage root.

Parameters

sourcePath

string

Source storage path.

destinationPath

string

Destination storage path.

Returns

Promise<void>

Throws

StorageFileNotFoundError when the source file is missing.

Overrides

QStorageEngineBase.move


moveTo()

moveTo(file, targetEngine, targetPath): Promise<void>

Defined in: storage/src/engine/QLocalStorageEngine.ts:208

Move a file to another storage engine.

Parameters

file

QStorageFile

Source storage file.

targetEngine

QStorageEngineBase

Target storage engine.

targetPath

string

Destination path in the target engine.

Returns

Promise<void>

Throws

StorageFileNotFoundError when the source file is missing.

Overrides

QStorageEngineBase.moveTo


new()

new(path, contents, options?): Promise<QStorageFile>

Defined in: storage/src/engine/QStorageEngineBase.ts:109

Create a new file from raw contents and return refreshed metadata.

Parameters

path

string

Storage path where the file should be stored.

contents

string | Buffer<ArrayBufferLike>

File contents (Buffer or string).

options?

Additional options.

encoding?

BufferEncoding

Text encoding when contents is a string and not base64. Defaults to utf-8 when isBase64 is false, otherwise binary.

fill?

boolean

Whether to return the entity with contents loaded.

isBase64?

boolean

When true, contents is already base64 encoded. Defaults to true for strings.

mimeType?

string

Override detected mime type.

Returns

Promise<QStorageFile>

Inherited from

QStorageEngineBase.new


read()

read(file): Promise<QStorageFile>

Defined in: storage/src/engine/QLocalStorageEngine.ts:114

Load file contents as base64.

Parameters

file

QStorageFile

Storage file to read.

Returns

Promise<QStorageFile>

Overrides

QStorageEngineBase.read


readStream()

readStream(path): Promise<ReadableStream>

Defined in: storage/src/engine/QLocalStorageEngine.ts:133

Read a file from local storage as a stream.

Parameters

path

string

Storage path to read.

Returns

Promise<ReadableStream>

Overrides

QStorageEngineBase.readStream


recordSpanError()

protected recordSpanError(span, err): void

Defined in: core/src/QObject.ts:45

Record an exception on an active span.

Parameters

span

TelemetrySpan

The span to record the error on.

err

unknown

The error to record.

Returns

void

Inherited from

QStorageEngineBase.recordSpanError


remove()

remove(path): Promise<void>

Defined in: storage/src/engine/QLocalStorageEngine.ts:224

Remove a local file.

Parameters

path

string

Storage path to remove.

Returns

Promise<void>

Throws

StorageFileNotFoundError when the target file is missing.

Overrides

QStorageEngineBase.remove


removeFolder()

removeFolder(path): Promise<void>

Defined in: storage/src/engine/QLocalStorageEngine.ts:237

Remove a folder and its contents.

Parameters

path

string

Storage folder path to remove.

Returns

Promise<void>

Overrides

QStorageEngineBase.removeFolder


save()

save(file, path): Promise<void>

Defined in: storage/src/engine/QLocalStorageEngine.ts:73

Save a file to local storage.

Parameters

file

QStorageFile

Storage file to save.

path

string

Storage path where the file should be stored.

Returns

Promise<void>

Throws

StorageFileContentsMissingError when there is no content to save.

Overrides

QStorageEngineBase.save


saveStream()

saveStream(path, stream): Promise<void>

Defined in: storage/src/engine/QLocalStorageEngine.ts:101

Save a stream to local storage without buffering contents.

Parameters

path

string

Storage path where the file should be stored.

stream

ReadableStream

Readable stream to store.

Returns

Promise<void>

Overrides

QStorageEngineBase.saveStream


setSpanAttribute()

protected setSpanAttribute(span, key, value): void

Defined in: core/src/QObject.ts:64

Set a single attribute on an active span.

Parameters

span

TelemetrySpan

The span to update.

key

string

Attribute key.

value

string | number | boolean

Attribute value.

Returns

void

Inherited from

QStorageEngineBase.setSpanAttribute


startSpan()

protected startSpan(spanName, options?): TelemetrySpan

Defined in: core/src/QObject.ts:26

Start a telemetry span for the given operation name. Returns undefined when no telemetry provider is active.

Parameters

spanName

string

Name of the span.

options?

TelemetrySpanOptions

Optional span attributes and kind.

Returns

TelemetrySpan

Inherited from

QStorageEngineBase.startSpan