-
Notifications
You must be signed in to change notification settings - Fork 650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Made chunk reading explicit when using read or pread #2772
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,6 +202,13 @@ public protocol ReadableFileHandleProtocol: FileHandleProtocol { | |
/// - chunkLength: The maximum length of the chunk to read as a ``ByteCount``. | ||
/// - Returns: A sequence of chunks read from the file. | ||
func readChunks(in range: Range<Int64>, chunkLength: ByteCount) -> FileChunks | ||
|
||
/// Returns an asynchronous sequence of chunks read from the file starting from the current file pointer. | ||
/// | ||
/// - Parameters: | ||
/// - size: The maximum length of the chunk to read as a ``ByteCount``. | ||
/// - Returns: A sequence of chunks read from the file. | ||
func readChunksFromFilePointer(chunkLength size: ByteCount) -> FileChunks | ||
Comment on lines
+206
to
+211
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't quite what I had in mind. Rather than adding new API I think we should use the type of the file to determine how to do the read inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would make the checks that happen inside of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also means that calling readToEnd will stat the file twice. I’m trying out your recommended solution and it also causes problems because if we check the file type in the FileChunks initializer, then that means the function has to be async throws. But the readChunks function from |
||
} | ||
|
||
// MARK: - Read chunks with default chunk length | ||
|
@@ -415,7 +422,7 @@ extension ReadableFileHandleProtocol { | |
var accumulator = ByteBuffer() | ||
accumulator.reserveCapacity(readSize) | ||
|
||
for try await chunk in self.readChunks(in: ..., chunkLength: .mebibytes(8)) { | ||
for try await chunk in self.readChunksFromFilePointer(chunkLength: .mebibytes(8)) { | ||
accumulator.writeImmutableBuffer(chunk) | ||
if accumulator.readableBytes > maximumSizeAllowed.bytes { | ||
throw FileSystemError( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's any reason to change these names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't
entireFile
misleading because it read from the current file pointer, not from the beginning of the file?