Skip to content

Commit

Permalink
Support ASCII_NO_TRAILING_BLANKS
Browse files Browse the repository at this point in the history
Signed-off-by: Qi Liang <[email protected]>
  • Loading branch information
std4lqi committed Dec 12, 2023
1 parent b4a1ee7 commit eae2796
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ await connection.uploadDataset(input, 'HLQ.HOSTS', "LRECL=80 RECFM=FB");
##### Parameter

* dsn - _string_ - Specify a full qualified dataset name, or USS file name. It **CAN NOT** contain any wildcard (*).
* transferMode - _TransferMode_ - `TransferMode.ASCII`, `TransferMode.BINARY`, `TransferMode.ASCII_STRIP_EOL`, `TransferMode.ASCII_RDW`, or `TransferMode.BINARY_RDW`. When downloading a text dataset, transferMode should be either `TransferMode.ASCII` or `TransferMode.ASCII_STRIP_EOL` so that z/OS FTP service converts `EBCDIC` characters to `ASCII`. `TransferMode.ASCII_STRIP_EOL` asks z/OS FTP service not to append a `CLRF` to the end of each record. `TransferMode.ASCII_RDW` and `TransferMode.BINARY_RDW` support to download variable length dataset, which add 4-byte Record Description Word (RDW) at the beginning of each record.
* transferMode - _TransferMode_ - `TransferMode.ASCII`, `TransferMode.BINARY`, `TransferMode.ASCII_STRIP_EOL`, `TransferMode.ASCII_RDW`, `TransferMode.ASCII_NO_TRAILING_BLANKS`, or `TransferMode.BINARY_RDW`. The `TransferMode.ASCII`, `TransferMode.ASCII_STRIP_EOL`, `TransferMode.ASCII_RDW`, or `TransferMode.ASCII_NO_TRAILING_BLANKS` asks z/OS FTP service to convert `EBCDIC` characters to `ASCII`. The `TransferMode.ASCII_STRIP_EOL` asks z/OS FTP service not to append a `CLRF` to the end of each record. The `TransferMode.ASCII_NO_TRAILING_BLANKS` asks z/OS FTP service to remove trailing blanks. The `TransferMode.ASCII_RDW` or `TransferMode.BINARY_RDW` supports to download variable length dataset, which add 4-byte Record Description Word (RDW) at the beginning of each record.
* stream - _boolean_ - `true` if you want to obtain a [ReadableStream](https://nodejs.org/api/stream.html#stream_readable_streams) of the data set content, or `false` to read a full dataset into memory (in Buffer). The buffer accepts up to 4MB data. For large dataset, use `stream=true` instead.
* siteParams - _string_ - Add extra site parameters, for example, 'sbd=(IBM-1047,ISO8859-1)' for encoding setting.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zos-node-accessor",
"version": "2.0.8",
"version": "2.0.9",
"description": "Accessing z/OS dataset and interacting with JES in NodeJS way",
"main": "./lib/zosAccessor.js",
"types": "./lib/zosAccessor.d.ts",
Expand Down
8 changes: 8 additions & 0 deletions src/__test__/downloadDataset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ describe('The method of downloadDataset()', () => {
expect(contents2.toString().trim()).toBe('helloworld');
});

it('can get text contents from dataset with TransferMode.ASCII_NO_TRAILING_BLANKS', async () => {
await accessor.uploadDataset('hello\r\nworld ', dsn);
const contents1 = await accessor.downloadDataset(dsn, TransferMode.ASCII);
expect(contents1.toString().trim()).toBe('hello\r\nworld');
const contents2 = await accessor.downloadDataset(dsn, TransferMode.ASCII_NO_TRAILING_BLANKS);
expect(contents2.toString().trim()).toBe('helloworld');
});

it('can get text contents from dataset with TransferMode.BINARY', async () => {
await accessor.uploadDataset('hello\r\nworld', dsn);
const contents2 = await accessor.downloadDataset(dsn, TransferMode.BINARY);
Expand Down
7 changes: 7 additions & 0 deletions src/__test__/downloadFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ describe('The method of downloadFile()', () => {
expect(buffer.toString()).toBe(text);
});

it('can get USS file in ASCII_NO_TRAILING_BLANKS mode', async () => {
const text = 'Hello';

const buffer = await accessor.downloadFile(getUSSPath('nodeacc/hello_with_trailingblanks.txt'), TransferMode.ASCII_NO_TRAILING_BLANKS);
expect(buffer.toString()).toBe(text);
});

// Can get USS file in ASCII mode as STREAM
it('can get USS file in ASCII mode as STREAM', async () => {
const text = 'Hello\r\n';
Expand Down
39 changes: 29 additions & 10 deletions src/zosAccessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ export enum TransferMode {
ASCII = 'ascii',

/**
* The data is transferre in text mode, in which encoding conversion like ASCII/EBCDIC will happen, and
* The data is transferred in text mode, in which encoding conversion like ASCII/EBCDIC will happen, and
* the EOL of each record in dataset will be removed.
*/
ASCII_STRIP_EOL = 'ascii_strip_eol',

/**
* The data is transferred in text mode, in which the trailing blanks will be removed.
*/
ASCII_NO_TRAILING_BLANKS = 'ascii_no_trailing_blanks',

/**
* The data is transferred in binary mode, in which no encoding conversion will happen.
*/
Expand Down Expand Up @@ -435,23 +440,34 @@ class ZosAccessor {

// We still need this check in case the other TransferMode will be added in future.
if (transferMode !== TransferMode.ASCII &&
transferMode !== TransferMode.BINARY &&
transferMode !== TransferMode.ASCII_STRIP_EOL) {
transferMode !== TransferMode.ASCII_NO_TRAILING_BLANKS &&
transferMode !== TransferMode.ASCII_STRIP_EOL &&
transferMode !== TransferMode.BINARY) {
throw new Error('Unsupported data type: ' + transferMode);
}
let ftpCommand = ftpClient.binary;
if (transferMode === TransferMode.ASCII ||
transferMode === TransferMode.ASCII_NO_TRAILING_BLANKS ||
transferMode === TransferMode.ASCII_STRIP_EOL) {
ftpCommand = ftpClient.ascii;
}
let sbsendeol = 'SBSENDEOL=CRLF';
if (transferMode === TransferMode.ASCII_STRIP_EOL) {
sbsendeol = 'SBSENDEOL=NONE';
transferMode = TransferMode.ASCII;
}

let site = 'FILETYPE=SEQ TRAILINGBLANKS ' + sbsendeol;
let trailingBlanks = 'TRAILINGBLANKS';
if (transferMode === TransferMode.ASCII_NO_TRAILING_BLANKS) {
trailingBlanks = '';
}
let site = 'FILETYPE=SEQ ' + trailingBlanks + ' ' + sbsendeol;
if (siteParams) {
site += ' ' + siteParams;
}

// ftpClient.ascii() or ftpClient.binary()
ftpClient[transferMode]((err: Error) => {
ftpCommand((err: Error) => {
if (err) {
return deferred.reject(err);
}
Expand Down Expand Up @@ -495,11 +511,14 @@ class ZosAccessor {
* Downloads the specified dataset or member of patition dataset.
*
* @param dsn - Dataset name
* @param transferMode - TransferMode.ASCII, TransferMode.BINARY, TransferMode.ASCII_RDW, TransferMode.BINARY_RDW
* or TransferMode.ASCII_STRIP_EOL. When downloading a text dataset, transferMode should be
* either `TransferMode.ASCII` or `TransferMode.ASCII_STRIP_EOL` so that z/OS FTP service
* converts `EBCDIC` characters to `ASCII`. `TransferMode.ASCII_STRIP_EOL` asks z/OS FTP
* service not to append a `CLRF` to the end of each record. `TransferMode.ASCII_RDW` and
* @param transferMode - TransferMode.ASCII, TransferMode.ASCII_RDW, TransferMode.ASCII_STRIP_EOL,
* TransferMode.ASCII_NO_TRAILING_BLANKS, TransferMode.BINARY, or TransferMode.BINARY_RDW.
* The `TransferMode.ASCII`, ` TransferMode.ASCII_RDW`, `TransferMode.ASCII_STRIP_EOL`,
* or TransferMode.ASCII_NO_TRAILING_BLANKS asks z/OS FTP service to
* convert `EBCDIC` characters to `ASCII`. `TransferMode.ASCII_STRIP_EOL` asks z/OS FTP
* service not to append a `CLRF` to the end of each record. The
* `TransferMode.ASCII_NO_TRAILING_BLANKS` asks z/OS FTP service to remove trailing blanks.
* `TransferMode.ASCII_RDW` and
* `TransferMode.BINARY_RDW` support to download variable length dataset, which add 4-byte
* Record Description Word (RDW) at the beginning of each record.
* @param {boolean} stream - `true` if you want to obtain a `ReadStream` of the data set content, or `false`
Expand Down

0 comments on commit eae2796

Please sign in to comment.