Skip to content

Commit

Permalink
Removed streamFile deprecation + deactivated advancedETagComparison b…
Browse files Browse the repository at this point in the history
…y default (#3177)

* Update FileIO.swift

sha-256 digest set when file is written to system

* Introduced new streamFile method

Introduced new streamFile method which allows for advancedETag comparison. Deprecated the old one.

* Updated Unit Tests

Updates to remove deprecated warnings by using the new streamFile() method. Also removed some other deprecation warnings.

* Added more documentation

* Removed unnecessary CryptoKit import

* added closure return types

* incorporated first round of @0xTim's feedback

* added test cases to account for advanced/simple etags

* Incorporated PR comments

- adjusted faulty comment
- access storage directly to avoid concurrent overwrites of the entire storage

* Added test for legacy streamFile

* Deprecated method to silence warnings

* Warning fixes

* following @gwynne's style advice :)

* undone deprecation + default of new advancedEtagComparison

---------

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
Co-authored-by: Gwynne Raskind <gwynne@vapor.codes>
  • Loading branch information
3 people committed Apr 23, 2024
1 parent 0311f9a commit 3e3d65b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/Vapor/Middleware/FileMiddleware.swift
Expand Up @@ -40,7 +40,7 @@ public final class FileMiddleware: Middleware {
/// an absolute path from the public directory root. If `nil`, no default files are served.
/// - directoryAction: Determines the action to take when the request doesn't have a trailing slash but matches a directory.
/// - advancedETagComparison: The method used when ETags are generated. If true, a byte-by-byte hash is created (and cached), otherwise a simple comparison based on the file's last modified date and size.
public init(publicDirectory: String, defaultFile: String? = nil, directoryAction: DirectoryAction = .none, advancedETagComparison: Bool = true) {
public init(publicDirectory: String, defaultFile: String? = nil, directoryAction: DirectoryAction = .none, advancedETagComparison: Bool = false) {
self.publicDirectory = publicDirectory.addTrailingSlash()
self.defaultFile = defaultFile
self.directoryAction = directoryAction
Expand Down
1 change: 0 additions & 1 deletion Sources/Vapor/Utilities/FileIO.swift
Expand Up @@ -123,7 +123,6 @@ public struct FileIO: Sendable {
/// - mediaType: HTTPMediaType, if not specified, will be created from file extension.
/// - onCompleted: Closure to be run on completion of stream.
/// - returns: A `200 OK` response containing the file stream and appropriate headers.
@available(*, deprecated, message: "Use the new `streamFile` method which returns EventLoopFuture<Response>")
@preconcurrency public func streamFile(
at path: String,
chunkSize: Int = NonBlockingFileIO.defaultChunkSize,
Expand Down

0 comments on commit 3e3d65b

Please sign in to comment.