Encoding the stream myself using Base64Encode and flags set to 1 fixed my problem.

There is no CRLF anymore in my stream.

Here is my final solution (error handle ommited)

stream=##class(%FileBinaryStream).%New()
stream.Filename = filename
encodedStream = ##class(%GlobalBinaryStream).%New()
while ('stream.AtEnd) {
      d encodedStream.Write(##class(%SYSTEM.Encryption).Base64Encode(stream.Read(12000),1))
}
propertyPath = "PIDgrpgrp(1).ORCgrp(1).OBXgrp(1).OBX:5(1)"
seg=target.GetMutableSegmentAt($P(propertyPath,":",1),.tSC)
tSC = seg.StoreFieldStreamRaw(.encodedStream,$P(propertyPath,":",2))

Thanks Armin for your help.

Second option : An OBX:5 with the value ABCDEFGHIJKL (get rid of all crlf)

[Updated last comment with code]

I need to add a file inside the obx:5(1) segment as a base64 encoded stream.

I'm using the StoreFieldStreamBase64 method from EnsLib.HL7.Segment.

This method add extra escaped CRLF inside my OBX segment and i don't know why.

When i write the hl7 message on disk with the new OBX segment, i can't parse it anymore with an EnsLib.HL7.Service.FileService, the extra crlf character is the problem.

Maybe i'm doing something wrong in my way to process the file.

Hello, thanks for your answer.

Here is how i store the base64 stream inside my obx segment : 

stream=##class(%FileBinaryStream).%New()
stream.Filename = filename
propertyPath = "PIDgrpgrp(1).ORCgrp(1).OBXgrp(1).OBX:5(1)"
seg=target.GetMutableSegmentAt($P(propertyPath,":",1),.tSC)
tSC = seg.StoreFieldStreamBase64(.stream,$P(propertyPath,":",2),,0)

Here is the result :

JVBERi0xLjQKJeLjz9MKNCAwIG9iago8PC9UeXBlL1hPYmplY3QvQ29sb3JTcGFjZS9EZXZpY2VH\r\ncmF5L1N1YnR5cGUvSW1hZ2UvQml0c1BlckNvbXBvbmVudCA4L1dpZHRoIDEzOS9MZW5ndGggMTM3\r\nMi9IZWlnaHQgN

EX : OBX|1|RP|5142648||ABCD[CR][LF]EFGH[CR][LF]IJKL....

I don't know why there is multiple extra \r\n in the obx segment.

And when i use a EnsLib.HL7.Service.FileService, my HL7 Object OBX:5(1) hold only ABCD information.

Kami