Skip to main content
Version: Next

FileSystemStorageBackend

A file-system storage backend backed by the native @crawlee/fs-storage-native Rust extension.

The native extension owns the on-disk format, timestamps, item counting, request-queue locking and state persistence. This class is responsible for resolving the user-facing id / name / alias identifiers to native storages, caching the opened backends (so that storageExists, purge and teardown can operate over them), and exposing them through the @crawlee/types interfaces.

Implements

Index

Constructors

constructor

Properties

readonlydatasetsDirectory

datasetsDirectory: string

readonlykeyValueStoresDirectory

keyValueStoresDirectory: string

readonlylocalDataDirectory

localDataDirectory: string

optionalreadonlylogger

logger?: CrawleeLogger

readonlyrequestQueueAccess

requestQueueAccess: single | shared

readonlyrequestQueuesDirectory

requestQueuesDirectory: string

Methods

createDatasetBackend

  • Create (or open) a dataset backend. If id is provided, opens the dataset with that ID. If name is provided, opens an existing dataset with that name or creates a new one. If neither is provided, opens or creates the default dataset.


    Parameters

    Returns Promise<DatasetBackend<Dictionary>>

createKeyValueStoreBackend

  • Create (or open) a key-value store backend. If id is provided, opens the key-value store with that ID. If name is provided, opens an existing store with that name or creates a new one. If neither is provided, opens or creates the default key-value store.


    Parameters

    Returns Promise<KeyValueStoreBackend>

createRequestQueueBackend

  • Create (or open) a request queue backend. If id is provided, opens the request queue with that ID. If name is provided, opens an existing queue with that name or creates a new one. If neither is provided, opens or creates the default request queue.


    Parameters

    Returns Promise<RequestQueueBackend>

getStorageBackendCacheKey

  • getStorageBackendCacheKey(): string
  • Return a cache key that includes the resolved storage directory, so that two FileSystemStorageBackend instances pointing at different directories get separate cache partitions, by including the storage directory in the cache key.


    Returns string

purge

  • purge(): Promise<void>
  • Cleans up the run-scoped storages before the run starts, sweeping the storage directories so that leftovers from a previous process are caught too.


    Returns Promise<void>

storageExists

  • storageExists(id, type): Promise<boolean>
  • Check whether a storage with the given ID exists.

    Used internally to resolve ambiguous idOrName strings passed to Dataset.open(), KeyValueStore.open(), and RequestQueue.open().


    Parameters

    • id: string
    • type: Dataset | KeyValueStore | RequestQueue

    Returns Promise<boolean>

teardown

  • teardown(): Promise<void>
  • This method should be called at the end of the process, to ensure all data is saved.

    It persists the state of every opened request queue so that requests fetched but not yet handled are not stuck (until their lock expires) for the next consumer of the same on-disk queue.


    Returns Promise<void>