From 27648e70491644d332d7cc4b847249bdc9e11b4e Mon Sep 17 00:00:00 2001 From: Charles Hu Date: Wed, 14 May 2025 21:11:16 -0700 Subject: [PATCH 1/2] Remove the default output buffer limit --- Sources/Subprocess/IO/Output.swift | 12 +++++------- .../SubprocessTests+Unix.swift | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Sources/Subprocess/IO/Output.swift b/Sources/Subprocess/IO/Output.swift index e33292d..1148beb 100644 --- a/Sources/Subprocess/IO/Output.swift +++ b/Sources/Subprocess/IO/Output.swift @@ -46,7 +46,7 @@ public protocol OutputProtocol: Sendable, ~Copyable { #endif extension OutputProtocol { /// The max amount of data to collect for this output. - public var maxSize: Int { 128 * 1024 } + public var maxSize: Int { .max } } /// A concrete `Output` type for subprocesses that indicates that @@ -240,10 +240,9 @@ extension OutputProtocol where Self == FileDescriptorOutput { @available(SubprocessSpan, *) #endif extension OutputProtocol where Self == StringOutput { - /// Create a `Subprocess` output that collects output as - /// UTF8 String with 128kb limit. + /// Create a `Subprocess` output that collects output as UTF8 String public static var string: Self { - .init(limit: 128 * 1024, encoding: UTF8.self) + .init(limit: .max, encoding: UTF8.self) } } @@ -265,9 +264,8 @@ extension OutputProtocol { @available(SubprocessSpan, *) #endif extension OutputProtocol where Self == BytesOutput { - /// Create a `Subprocess` output that collects output as - /// `Buffer` with 128kb limit. - public static var bytes: Self { .init(limit: 128 * 1024) } + /// Create a `Subprocess` output that collects output as `Buffer` + public static var bytes: Self { .init(limit: .max) } /// Create a `Subprocess` output that collects output as /// `Buffer` up to limit it bytes. diff --git a/Tests/SubprocessTests/SubprocessTests+Unix.swift b/Tests/SubprocessTests/SubprocessTests+Unix.swift index f6a82c9..cbb3b28 100644 --- a/Tests/SubprocessTests/SubprocessTests+Unix.swift +++ b/Tests/SubprocessTests/SubprocessTests+Unix.swift @@ -955,6 +955,25 @@ extension SubprocessUnixTests { } #expect(result == .unhandledException(SIGKILL)) } + + @Test func testUnlimitedBufferByDefault() async throws { + guard #available(SubprocessSpan , *) else { + return + } + + // Make sure we can read long text from standard input + let expected: Data = try Data( + contentsOf: URL(filePath: theMysteriousIsland.string) + ) + // Launch cat with default output `.string` + let cat = try await Subprocess.run( + .path("/bin/cat"), + arguments: ["\(theMysteriousIsland.string)"] + ) + #expect(cat.terminationStatus.isSuccess) + // Make sure we read all bytes + #expect(cat.standardOutput!.data(using: .utf8) == expected) + } } // MARK: - Utils From 212047f21232826a6c462f9fc7549c61b21639c4 Mon Sep 17 00:00:00 2001 From: Charles Hu Date: Thu, 15 May 2025 13:58:25 -0700 Subject: [PATCH 2/2] Modify header doc to indicate that .string and .bytes outputs have unlimited buffer size --- Sources/Subprocess/IO/Output.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/Subprocess/IO/Output.swift b/Sources/Subprocess/IO/Output.swift index 1148beb..46b201a 100644 --- a/Sources/Subprocess/IO/Output.swift +++ b/Sources/Subprocess/IO/Output.swift @@ -241,6 +241,9 @@ extension OutputProtocol where Self == FileDescriptorOutput { #endif extension OutputProtocol where Self == StringOutput { /// Create a `Subprocess` output that collects output as UTF8 String + /// with an unlimited buffer size. The memory requirement for collecting + /// output is directly proportional to the size of the output + /// emitted by the child process. public static var string: Self { .init(limit: .max, encoding: UTF8.self) } @@ -264,7 +267,10 @@ extension OutputProtocol { @available(SubprocessSpan, *) #endif extension OutputProtocol where Self == BytesOutput { - /// Create a `Subprocess` output that collects output as `Buffer` + /// Create a `Subprocess` output that collects output as a `Buffer` + /// with an unlimited buffer size. The memory requirement for collecting + /// output is directly proportional to the size of the output + /// emitted by the child process. public static var bytes: Self { .init(limit: .max) } /// Create a `Subprocess` output that collects output as