Written by

Developer, analyst, qa, moderator at TECCOD
Question Dmitrij Vladimirov · Feb 10

CRLF to LF

For example we have a docker app that receives a .csv file from windows environment and then do some processing on it in docker linux environment.
 
Windows encode new line in CRLF format, but linux can understand only LF and throw an unexpected errors like
 

ERROR #7207: Datatype value '100 ' is not a valid number > ERROR #5802: Datatype validation failed on property 'esh.i14y.csv.CelciusCSV.Record:Temperature', with value equal to "100 "


Is there a way to convert new line logic inside iris container in cases when .csv file (and other possible files) comes from windows environment ?

Product version: IRIS 2024.3

Comments

Enrico Parisi · Feb 10

What are you using to read the csv file in IRIS?

Can you provide a small sample code?

0
Dmitrij Vladimirov  Feb 10 to Enrico Parisi

The code piece that reading file 
 

If '$IsObject(pStream) {
            Set tFilename = pStream
            Set pStream = ##class(%IO.FileStream).%New()
            Do pStream.Open(tFilename,,pTimeout,"UTF-8", .tStatus)
            If$$$ISERR(tStatus) Quit
        }
0
Julius Kavay · Feb 10

Before you start reading, set the lineterminator property to the desired value

do myStream.Rewind()
 set myStream.LineTerminator=$c(13,10)  // or $c(10)// or more generalset myStream.LineTerminator=$case($zversion(1), 2:$c(13,10), 3:$c(10), :"")
 
 // now start readingset line = myStream.ReadLine()
 ...
 ...
0
Mike Henderson · Feb 17

For this specific case I recommend using the %SQL_Util.CSV stored procedure since it handles CRLF on linux correctly. Note - RFC 4180 uses CRLF as the line terminator.

In situations where you need to manually read line-by-line simply trim trailing whitespace including CR

While 'file.AtEnd {
  Set line = file.ReadLine()
  Set line = $ZStrip(line, "<>W", $C(13))
  // ...
}
0