Reference constructor

Reference(
  1. {required FusabaseStorage storage,
  2. required String fullPath,
  3. Reference? parent}
)

Constructs a new Reference instance.

Parameters:

  • storage: The associated storage instance (required).
  • fullPath: The full path to the object.
  • parent: Optional parent reference.

Throws: Error if the path is invalid (starts or ends with '/').

Returns: A new Reference instance.

Example:

var ref = Reference(storage: myStorage, fullPath: 'images/stars.jpg');

Implementation

Reference({
  required this.storage,
  required String fullPath,
  Reference? parent,
}) : _bucket = storage.bucket,
     _name = "",
     __logLevel = storage.app.logLevel,
     _parent = parent {
  fullPath = fullPath.trim();
  if (fullPath.isNotEmpty &&
      (fullPath[0] == '/' || fullPath[fullPath.length - 1] == '/')) {
    throw Utils.storageErrorHandler(
      400,
      StorageErrorMessages.format(StorageErrorMessages.INCORRECT_PATH, [
        fullPath,
      ]),
      null,
    );
  }

  List<String> tokens = fullPath.split('/');
  _name = tokens.removeAt(tokens.length - 1);

  _parent =
      (tokens.isEmpty && _name == "")
          ? null
          : Reference(
            storage: storage,
            fullPath: tokens.join("/"),
            parent: _parent,
          );

  _root = ((_parent == null) ? this : _parent?._root)!;
}