Skip to content

Commit

Permalink
Merge pull request #90 from IBM/add-site-params-to-download-dataset
Browse files Browse the repository at this point in the history
Add siteParams to downloadDataset(...)
  • Loading branch information
std4lqi authored Jun 19, 2023
2 parents 3d2740e + 109f658 commit 3e32cc8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,14 @@ await connection.uploadDataset(input, 'HLQ.HOSTS', "LRECL=80 RECFM=FB");

#### Download MVS dataset

`downloadDataset(dsn: string, transferMode: TransferMode = TransferMode.ASCII, stream = false)` - Downloads the specified dataset or member of patition dataset.
`downloadDataset(dsn: string, transferMode: TransferMode = TransferMode.ASCII, stream = false, siteParams?: string)` - Downloads the specified dataset or member of patition dataset.

##### 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.
* 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.

##### Return

Expand Down
2 changes: 1 addition & 1 deletion 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.6",
"version": "2.0.7",
"description": "Accessing z/OS dataset and interacting with JES in NodeJS way",
"main": "./lib/zosAccessor.js",
"types": "./lib/zosAccessor.d.ts",
Expand Down
5 changes: 5 additions & 0 deletions src/__unit__/zosAccessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ describe('z/OS node accessor', () => {
expect(mockFtp4.site).toBeCalledWith('rdw', expect.any(Function));
});

it('can download dataset with site params', async () => {
await client.downloadDataset('dsn', TransferMode.BINARY, true, 'site params');
expect(mockFtp4.site).toBeCalledWith('FILETYPE=SEQ TRAILINGBLANKS SBSENDEOL=CRLF site params', expect.any(Function));
});

it('can convert allocation parameter object to string', async () => {
await client.uploadDataset('hello', uploadDSN, TransferMode.ASCII, { LRECL: 80, RECFM: 'FB'});
expect(mockFtp4.site).toBeCalledWith('FILETYPE=SEQ LRECL=80 RECFM=FB', expect.any(Function));
Expand Down
19 changes: 13 additions & 6 deletions src/zosAccessor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************/
/* */
/* Copyright (c) 2017, 2021 IBM Corp. */
/* Copyright (c) 2017, 2023 IBM Corp. */
/* All rights reserved. This program and the accompanying materials */
/* are made available under the terms of the Eclipse Public License v1.0 */
/* which accompanies this distribution, and is available at */
Expand Down Expand Up @@ -429,7 +429,7 @@ class ZosAccessor {
}

private async download(dsn: string, transferMode: TransferMode = TransferMode.ASCII,
stream = false): Promise<Buffer | ReadStream> {
stream = false, siteParams?: string): Promise<Buffer | ReadStream> {
const deferred = Q.defer<Buffer | ReadStream>();
const ftpClient = this.client;

Expand All @@ -445,12 +445,17 @@ class ZosAccessor {
transferMode = TransferMode.ASCII;
}

let site = 'FILETYPE=SEQ TRAILINGBLANKS ' + sbsendeol;
if (siteParams) {
site += ' ' + siteParams;
}

// ftpClient.ascii() or ftpClient.binary()
ftpClient[transferMode]((err: Error) => {
if (err) {
return deferred.reject(err);
}
ftpClient.site('FILETYPE=SEQ TRAILINGBLANKS ' + sbsendeol, (err1: Error) => {
ftpClient.site(site, (err1: Error) => {
if (err1) {
return deferred.reject(err1);
}
Expand Down Expand Up @@ -500,10 +505,12 @@ class ZosAccessor {
* @param {boolean} stream - `true` if you want to obtain a `ReadStream` 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.
* @param {string} siteParams - Add extra site parameters, for example, 'sbd=(IBM-1047,ISO8859-1)' for encoding
* setting.
* @returns `ReadStream` or `Buffer`
*/
public async downloadDataset(dsn: string, transferMode: TransferMode = TransferMode.ASCII,
stream = false): Promise<Buffer | ReadStream> {
stream = false, siteParams?: string): Promise<Buffer | ReadStream> {
if (transferMode === TransferMode.ASCII_RDW || transferMode === TransferMode.BINARY_RDW) {
if (transferMode === TransferMode.ASCII_RDW) {
transferMode = TransferMode.ASCII;
Expand All @@ -516,12 +523,12 @@ class ZosAccessor {
if (err) {
return deferred.reject(err);
}
const file = await this.download(dsn, transferMode, stream);
const file = await this.download(dsn, transferMode, stream, siteParams);
deferred.resolve(file);
});
return deferred.promise;
}
return await this.download(dsn, transferMode, stream);
return await this.download(dsn, transferMode, stream, siteParams);
}

/**
Expand Down

0 comments on commit 3e32cc8

Please sign in to comment.