Skip to content

Platform Storage

Platform-specific storage implementations for optimized file operations.

Base Classes

PlatformStorageBase(value: Union[int, float] = 0, unit: StorageUnit = StorageUnit.BYTES)

Bases: Storage

Base class for platform-specific storage implementations.

This class extends the base Storage class and provides a foundation for platform-specific optimizations while maintaining compatibility with the base Storage interface.

Parameters:

Name Type Description Default
value Union[int, float]

The numerical value of the storage (defaults to 0).

0
unit StorageUnit

The unit of the storage value (defaults to BYTES).

BYTES

Functions

get_platform_info() -> Dict[str, Any]

Get platform-specific information.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: Dictionary containing platform information.

Platform Implementations

WindowsStorage(value: Union[int, float] = 0, unit: StorageUnit = StorageUnit.BYTES)

Bases: PlatformStorageBase

Windows-specific storage implementation.

This class provides Windows-optimized functionality for storage operations, including NTFS-specific features and Windows API optimizations where beneficial.

Features
  • Optimized file size retrieval using Windows APIs when available
  • Support for Windows-specific file attributes
  • NTFS stream and compression awareness
  • Junction and symbolic link handling

Functions

get_size_from_path(path: Union[str, Path]) -> Storage

Get file or directory size with Windows-specific optimizations.

This method provides enhanced file size calculation for Windows, including support for compressed files, sparse files, and proper handling of junctions and symbolic links.

Parameters:

Name Type Description Default
path Union[str, Path]

The path to the file or directory.

required

Returns:

Name Type Description
Storage Storage

Storage instance representing the total size.

Raises:

Type Description
FileNotFoundError

If the path does not exist.

PermissionError

If access to the path is denied.

OSError

If an OS-level error occurs.

Examples:

>>> win_storage = WindowsStorage()
>>> size = win_storage.get_size_from_path("C:\Windows\System32")
>>> print(size.auto_scale())
2.3 GIB

get_platform_info() -> Dict[str, Any]

Get Windows-specific platform information.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: Dictionary containing Windows platform information.

LinuxStorage(value: Union[int, float] = 0, unit: StorageUnit = StorageUnit.BYTES)

Bases: PlatformStorageBase

Linux-specific storage implementation.

This class provides Linux-optimized functionality for storage operations, including support for various Linux file systems and GNU/Linux specific tools and APIs.

Features
  • Optimized file size retrieval using Linux tools (du, find)
  • Support for Linux-specific file attributes
  • Symbolic link and mount point awareness
  • File system type detection and optimization

Functions

get_size_from_path(path: Union[str, Path]) -> Storage

Get file or directory size with Linux-specific optimizations.

This method provides enhanced file size calculation for Linux, including optimized directory traversal and proper handling of symbolic links, mount points, and special files.

Parameters:

Name Type Description Default
path Union[str, Path]

The path to the file or directory.

required

Returns:

Name Type Description
Storage Storage

Storage instance representing the total size.

Raises:

Type Description
FileNotFoundError

If the path does not exist.

PermissionError

If access to the path is denied.

OSError

If an OS-level error occurs.

Examples:

>>> linux_storage = LinuxStorage()
>>> size = linux_storage.get_size_from_path("/usr/lib")
>>> print(size.auto_scale())
1.8 GIB

get_platform_info() -> Dict[str, Any]

Get Linux-specific platform information.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: Dictionary containing Linux platform information.

MacStorage(value: Union[int, float] = 0, unit: StorageUnit = StorageUnit.BYTES)

Bases: PlatformStorageBase

macOS-specific storage implementation.

This class provides macOS-optimized functionality for storage operations, including support for HFS+/APFS specific features and macOS APIs.

Features
  • Optimized file size retrieval using macOS tools
  • Support for macOS-specific file attributes (resource forks, extended attributes)
  • APFS snapshot and clone awareness
  • Spotlight integration for metadata

Functions

get_size_from_path(path: Union[str, Path]) -> Storage

Get file or directory size with macOS-specific optimizations.

This method provides enhanced file size calculation for macOS, including proper handling of resource forks, extended attributes, and APFS-specific features.

Parameters:

Name Type Description Default
path Union[str, Path]

The path to the file or directory.

required

Returns:

Name Type Description
Storage Storage

Storage instance representing the total size.

Raises:

Type Description
FileNotFoundError

If the path does not exist.

PermissionError

If access to the path is denied.

OSError

If an OS-level error occurs.

Examples:

>>> mac_storage = MacStorage()
>>> size = mac_storage.get_size_from_path("/Applications")
>>> print(size.auto_scale())
15.7 GIB

get_platform_info() -> Dict[str, Any]

Get macOS-specific platform information.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: Dictionary containing macOS platform information.