Member Junction
    Preparing search index...

    A FileStorageBase driver over one directory of the server's file system.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _accountId: string

    The ID of the FileStorageAccount this driver instance is operating for. Set during initialization via the config parameter.

    _accountName: string

    The name of the FileStorageAccount (for logging/display purposes).

    providerName: "Local File System Storage" = 'Local File System Storage'

    The name of this storage provider, used in error messages and logging. Each implementation must define this property with a descriptive name.

    Accessors

    • get AccountId(): string

      Gets the account ID this driver instance is operating for. Returns undefined if the driver was not initialized with an account.

      Returns string

    • get AccountName(): string

      Gets the account name this driver instance is operating for. Returns undefined if the driver was not initialized with an account.

      Returns string

    • get SupportsPreAuthDownload(): boolean

      Returns true if the storage provider driver supports generating pre-authenticated direct download URLs.

      Returns boolean

      true if the driver supports pre-authenticated downloads; false otherwise.

    • get SupportsPreAuthUpload(): boolean

      Returns true if the storage provider driver supports generating pre-authenticated direct upload URLs.

      When true, callers can invoke CreatePreAuthUploadUrl to get a direct cloud storage upload URL and send raw binary data directly to the storage service without routing through intermediate servers.

      Returns boolean

      true if the driver supports pre-authenticated uploads; false otherwise.

    • get SupportsStreaming(): boolean

      Indicates whether this provider supports streaming/ranged downloads via GetObjectStream.

      The base default is false. Streaming-capable drivers override this getter to return true. Callers MUST check this getter before calling GetObjectStream, or be ready to catch StreamingNotSupportedError.

      Returns boolean

      true if the provider can serve ranged, streamed reads; false otherwise.

      if (storage.SupportsStreaming) {
      const { Stream, ContentRange } = await storage.GetObjectStream({ objectId, Range: { Start, End } });
      Stream.pipe(httpResponse);
      } else {
      const buffer = await storage.GetObject({ objectId });
      httpResponse.end(buffer);
      }

    Methods

    • Copies a file under the root, creating the destination's directories. A symlink at either key is refused: the copy would read the file the source link points at, or write through the destination link into the file it points at.

      Parameters

      • sourceObjectName: string
      • destinationObjectName: string

      Returns Promise<boolean>

    • Deletes a directory below the root (the root itself is refused). Non-recursive removes only an empty directory — a non-empty one surfaces the OS error (ENOTEMPTY); recursive removes the whole tree. A missing directory counts as deleted either way.

      Parameters

      • directoryPath: string
      • Optionalrecursive: boolean

      Returns Promise<boolean>

    • Releases any resources (keep-alive sockets, connection pools, credential timers) held by this driver's underlying SDK client. Called by FileStorageEngine before a cached driver instance is dropped or replaced (e.g. RefreshDriverCache(), or the on-demand GetDriver() fallback overwriting a stale entry) so the old client doesn't keep its socket pool alive after nothing can reach it.

      Default is a no-op: most storage SDKs used here (Azure, Box, Dropbox, Google) don't expose an explicit client-teardown API, so there is nothing safe to call. Drivers whose SDK client does expose one (see AWSFileStorage.Dispose) should override this.

      Returns void

    • Streams an object's content (optionally a byte range) without buffering the whole object in memory.

      Use this instead of GetObject when serving large media (audio/video) over HTTP — pipe the returned ObjectStreamResult.Stream directly to the HTTP response and propagate ContentType/ContentLength/ContentRange to the response headers. GetObject returns the full object as a Buffer and is appropriate only for small payloads you need fully in memory.

      Range semantics: params.Range is an inclusive byte range ({ Start, End }), matching the HTTP Range/Content-Range model. Omit End to stream from Start to EOF. When a range is honored, the result's ContentRange carries the actual Start/End returned and the object's Total size — enough to emit Content-Range: bytes Start-End/Total and a 206 Partial Content status. When no Range is supplied, the whole object is streamed and ContentRange is omitted.

      Capability gating: The base class provides a default implementation that throws StreamingNotSupportedError. This means drivers that don't support streaming inherit the throw automatically (no boilerplate stubs) and SupportsStreaming stays false. Callers MUST therefore either check SupportsStreaming first, or be prepared to catch StreamingNotSupportedError and fall back to GetObject.

      Parameters

      • params: GetObjectStreamParams

        Object identifier (prefer objectId, fall back to fullPath) plus an optional inclusive Range.

      Returns Promise<ObjectStreamResult>

      A Promise resolving to an ObjectStreamResult with the readable stream and accompanying content metadata.

      if (!storage.SupportsStreaming) {
      // fall back to a full buffered read
      }
      const result = await storage.GetObjectStream({
      objectId: 'media/big-video.mp4',
      Range: { Start: 0, End: 1_048_575 }, // first 1 MiB, inclusive
      });
      res.status(result.ContentRange ? 206 : 200);
      if (result.ContentType) res.setHeader('Content-Type', result.ContentType);
      if (result.ContentLength != null) res.setHeader('Content-Length', String(result.ContentLength));
      if (result.ContentRange) {
      const { Start, End, Total } = result.ContentRange;
      res.setHeader('Content-Range', `bytes ${Start}-${End}/${Total}`);
      }
      result.Stream.pipe(res);

      StreamingNotSupportedError if the provider does not support streaming (the base default).

    • The canonical form of an object key for this storage — what the storage access checks compare when they ask whether an object backs an MJ: Files row (see StorageAccessEvaluator.UnreadableTrackedObjectKeys). Both the key a client sends and the key a row stores go through this one method, so two spellings this driver resolves to the same object must canonicalize alike.

      The default (NormalizeStorageObjectKey) trims the key, collapses runs of / and strips leading and trailing / — right for every driver whose spellings differ only in slashes. A driver that adds its own root or prefix to SOME keys and not others (S3's key prefix) overrides this to return the key relative to that root. Case is preserved; callers compare case-insensitively.

      Parameters

      • objectKey: string

        An object key as a client or an MJ: Files row spells it

      Returns string

      The canonical key: relative to this driver's root, no leading/trailing /, no repeated /

    • Writes the bytes atomically (a temporary file in the same directory, renamed over the key), creating parent directories; a symlink at the key is refused rather than replaced. The content type and metadata are not stored: a plain file system has nowhere to keep them.

      Parameters

      • objectName: string
      • data: Buffer
      • Optional_contentType: string
      • Optional_metadata: Record<string, string>

      Returns Promise<boolean>

    • Helper method to throw an UnsupportedOperationError with appropriate context. This method simplifies implementation of methods not supported by specific providers.

      Parameters

      • methodName: string

        The name of the method that is not supported

      Returns never

      UnsupportedOperationError with information about the unsupported method and provider