From b7647081b694fcc4f4c89d1c42b3f29dbb9b919a Mon Sep 17 00:00:00 2001 From: David Millington Date: Thu, 11 Dec 2025 20:15:19 +0200 Subject: [PATCH] Fire 304: Toffee File.WriteBytes of 0 length creates empty file; Binary.ToArray of 0 length creates empty 0-element array --- Source/RemObjects.Elements.RTL/Binary.pas | 8 ++++++-- Source/RemObjects.Elements.RTL/File.pas | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/RemObjects.Elements.RTL/Binary.pas b/Source/RemObjects.Elements.RTL/Binary.pas index 5686d31..20ae40c 100755 --- a/Source/RemObjects.Elements.RTL/Binary.pas +++ b/Source/RemObjects.Elements.RTL/Binary.pas @@ -306,8 +306,12 @@ constructor Binary(Bin: ImmutableBinary); {$IF COOPER} result := fData.toByteArray as not nullable; {$ELSEIF TOFFEE} - result := new Byte[mapped.length]; - mapped.getBytes(result) length(mapped.length); + if mapped.length = 0 then + exit [] + else begin + result := new Byte[mapped.length]; + mapped.getBytes(result) length(mapped.length); + end; {$ELSEIF ECHOES OR ISLAND} result := mapped.ToArray as not nullable; {$ENDIF} diff --git a/Source/RemObjects.Elements.RTL/File.pas b/Source/RemObjects.Elements.RTL/File.pas index 7cf1605..048fee7 100644 --- a/Source/RemObjects.Elements.RTL/File.pas +++ b/Source/RemObjects.Elements.RTL/File.pas @@ -371,7 +371,10 @@ constructor File(aPath: not nullable String); class method File.WriteBytes(aFileName: String; Content: array of Byte); begin {$IF TOFFEE} - (new Binary(Content) as NSData).writeToURL(NSURL.fileURLWithPath(aFileName)) atomically(true); + if length(Content) > 0 then + (new Binary(Content) as NSData).writeToURL(NSURL.fileURLWithPath(aFileName)) atomically(true) + else + NSData.data.writeToURL(NSURL.fileURLWithPath(aFileName)) atomically(true); {$ELSE} var Handle := new FileHandle(aFileName, FileOpenMode.Create); try