Files
swift-nio/Sources/NIOFileSystem/ByteCount.swift
T
George Barnett f80c69f84b Add NIOFilesystem (#2615)
Motivation:

I/O is typically blocking, but options for interacting with the
filesystem using `async` APIs are limited. This change adds a new module
to NIO, `NIOFileSystem`. At the moment this is exposed as the
`_NIOFileSystem` product while users get a chance to try it out and
provide feedback.

During this time the API of `NIOFileSystem` is subject to change.
Breaking changes will come in _minor_ NIO releases and additive changes
may come in _patch_ releases of NIO.

Modifications:

- Add `NIOFileSystem`, `NIOFileSystemFoundationCompat`,
  `NIOFileSystemTests`, `NIOFileSystemIntegrationTests`, and
  `NIOFileSystemFoundationCompatTests`.
- Update docs
- Update CNIOLinux and CNIODarwin shims

Result:

File system can be accessed via `async` APIs
2024-01-16 03:30:26 -08:00

80 lines
2.6 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2023 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
/// Represents the number of bytes.
public struct ByteCount: Hashable, Sendable {
/// The number of bytes
public var bytes: Int64
/// Returns a ``ByteCount`` with a given number of bytes
/// - Parameter count: The number of bytes
public static func bytes(_ count: Int64) -> ByteCount {
return ByteCount(bytes: count)
}
/// Returns a ``ByteCount`` with a given number of kilobytes
///
/// One kilobyte is 1000 bytes.
///
/// - Parameter count: The number of kilobytes
public static func kilobytes(_ count: Int64) -> ByteCount {
return ByteCount(bytes: 1000 * count)
}
/// Returns a ``ByteCount`` with a given number of megabytes
///
/// One megabyte is 1,000,000 bytes.
///
/// - Parameter count: The number of megabytes
public static func megabytes(_ count: Int64) -> ByteCount {
return ByteCount(bytes: 1000 * 1000 * count)
}
/// Returns a ``ByteCount`` with a given number of gigabytes
///
/// One gigabyte is 1,000,000,000 bytes.
///
/// - Parameter count: The number of gigabytes
public static func gigabytes(_ count: Int64) -> ByteCount {
return ByteCount(bytes: 1000 * 1000 * 1000 * count)
}
/// Returns a ``ByteCount`` with a given number of kibibytes
///
/// One kibibyte is 1024 bytes.
///
/// - Parameter count: The number of kibibytes
public static func kibibytes(_ count: Int64) -> ByteCount {
return ByteCount(bytes: 1024 * count)
}
/// Returns a ``ByteCount`` with a given number of mebibytes
///
/// One mebibyte is 10,485,760 bytes.
///
/// - Parameter count: The number of mebibytes
public static func mebibytes(_ count: Int64) -> ByteCount {
return ByteCount(bytes: 1024 * 1024 * count)
}
/// Returns a ``ByteCount`` with a given number of gibibytes
///
/// One gibibyte is 10,737,418,240 bytes.
///
/// - Parameter count: The number of gibibytes
public static func gibibytes(_ count: Int64) -> ByteCount {
return ByteCount(bytes: 1024 * 1024 * 1024 * count)
}
}