Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


This API writes to an IBM i IFS file and performs optional text conversion. If the file already exists, it is deleted and re-created.

Parameters

  1. Path (String) - Path to the IFS file to write.
  2. Data (Buffer) - A Buffer instancing containing the data to write to the file.
  3. File CCSID (Number/optional) – Specifies the CCSID attribute of the file. If omitted or set to zero, the IBM i job CCSID will be used.
  4. Data CCSID (Number/optional) - Specifies the CCSID of the data to write to the file. The data will be converted from this CCSID to the file CCSID. If this parameter is omitted or set to zero, the data will be converted from the CCSID of the IBM i job to the file CCSID. If set to 65535 no conversion will be done.

Exception Handling

An Error instance will be thrown if there are any problems writing the file.

Examples

Code Block
languagejavascript
titleWrite JavaScript String to Text File in EBCDIC 37
var buffer = Buffer.from("Hello, world.", "utf8");
pjs.writeIFSFile("/home/rfite/ebcdic.txt", buffer, 37, 1208);


Code Block
languagejavascript
titleWrite EBCDIC Field Data to UTF8 Text File
  pjs.define("myfield", { type: "char", length: 13, initValue: "Hello, world." });
  pjs.writeIFSFile("/home/rfite/utf8.txt", pjs.getBuffer(myfield), 1208, 37);


Code Block
languagejavascript
titleWrite UTF-8 Data to File Without Conversion
  var buffer = Buffer.from("Hello, world.", "utf8");
  pjs.writeIFSFile("/home/rfite/utf8.txt", buffer, 1208, 65535);