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
Prevent BufferedWriter from producing empty files #2677
Prevent BufferedWriter from producing empty files #2677
Conversation
Motivation: In the current implementation, if the users forget to call 'flush()' on the writer when creating a new file with 'withFileHandle(forWritingAt:options:execute)' the newly created file is empty. Modifications: - Added the 'withBufferedWriter()' method for the 'WritableFileHandleProtocol' and implemented it for the WriteFileHandle and 'ReadWriteFilehandle'. The method calls flush on the bufferedWriter after executing the closure that writes the contents to the file as indicated by the user. Result: Users can now use the 'withBufferedWriter' method instead of instantiating the bufferedWriter themselves, reducing the possibility of omitting 'flush()'. TO DO: - documentthe method - implement tests
@swift-server-bot add to allowlist |
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.
Couple of doc nits but looks good otherwise!
/// | ||
/// - Parameters: | ||
/// - body: The closure that writes the contents to the buffer created in this method. | ||
/// - Returns: The result of the executed closure. |
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.
Returns:
shouldn't be indented here, otherwise it's treated as documentation for a parameter
Preventing BufferedWriter from producing empty files
Motivation:
In the current implementation, if the users forget to call 'flush()' on the writer when creating a new file with 'withFileHandle(forWritingAt:options:execute)' the newly created file is empty.
Modifications:
Implemented the 'withBufferedWriter()' method for the 'WriteFileHandle'. The method calls flush on the bufferedWriter after executing the closure that writes the contents to the buffer as indicated by the user.
Result:
Users can now use the 'withBufferedWriter' method instead of instantiating the bufferedWriter themselves, reducing the possibility of omitting 'flush()'.