diff --git a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts index 339aee57a4..cdf3a05e71 100644 --- a/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts +++ b/packages/zosfiles/__tests__/__system__/methods/download/Download.system.test.ts @@ -1081,53 +1081,91 @@ describe.each([false, true])("Download Data Set - Encoded: %s", (encoded: boolea expect(fileContents).toEqual(testData); }); - - it("should upload and download file with correct encoding", async () => { - let response: any; - - // Upload binary or encoded file - const uploadFile: string = encoded ? "downloadEncodingCheck.txt" : "downloadEncodingCheckBinary.txt"; - let downloadResponse: any; - let error: any; - - // Use text file as to get proper response from getRemoteEncoding() - const ussnameAsTxt = ussname + ".txt"; - try { - response = runCliScript(__dirname + - `/__resources__/${encoded ? "upload_file_to_uss.sh" : "upload_file_to_uss_binary.sh"}`, testEnvironment, [ - defaultSystem.tso.account, - defaultSystem.zosmf.host, - defaultSystem.zosmf.port, - defaultSystem.zosmf.user, - defaultSystem.zosmf.password, - defaultSystem.zosmf.rejectUnauthorized, - __dirname + "/__resources__/testfiles/" + uploadFile, - ussnameAsTxt, - encoded ? "1047" : true - ]); - downloadResponse = runCliScript(__dirname + "/__resources__/download_file.sh", testEnvironment, [ - defaultSystem.tso.account, - defaultSystem.zosmf.host, - defaultSystem.zosmf.port, - defaultSystem.zosmf.user, - defaultSystem.zosmf.password, - defaultSystem.zosmf.rejectUnauthorized, - ussnameAsTxt, - __dirname + `/__resources__/${encoded ? ".zosattributes" : ".zosattributes-binary"}` - ]); - } catch (err) { - error = err; - } - - expect(error).toBeFalsy(); - expect(response).toBeTruthy(); - expect(downloadResponse).toBeTruthy(); - - // Compare the downloaded contents to those uploaded - const fileContents = fs.readFileSync(`${testEnvironment.workingDir}/${posix.basename(ussnameAsTxt)}`).toString(); - expect(fileContents).toEqual(fs.readFileSync(__dirname + "/__resources__/testfiles/" + uploadFile).toString()); - }); - + describe.each([false, true])( + "Download Data Set - Binary: %s", + (binary: boolean) => { + it("should upload and download file with correct encoding", async () => { + let response: any; + + // Upload binary or encoded file + const uploadFile: string = binary + ? "downloadEncodingCheck.txt" + : "downloadEncodingCheckBinary.txt"; + let downloadResponse: any; + let error: any; + + // Use text file as to get proper response from getRemoteEncoding() + const ussnameAsTxt = ussname + ".txt"; + try { + response = runCliScript( + __dirname + + `/__resources__/${ + binary + ? "upload_file_to_uss.sh" + : "upload_file_to_uss_binary.sh" + }`, + testEnvironment, + [ + defaultSystem.tso.account, + defaultSystem.zosmf.host, + defaultSystem.zosmf.port, + defaultSystem.zosmf.user, + defaultSystem.zosmf.password, + defaultSystem.zosmf.rejectUnauthorized, + __dirname + + "/__resources__/testfiles/" + + uploadFile, + ussnameAsTxt, + binary ? "1047" : true, + ] + ); + downloadResponse = runCliScript( + __dirname + "/__resources__/download_file.sh", + testEnvironment, + [ + defaultSystem.tso.account, + defaultSystem.zosmf.host, + defaultSystem.zosmf.port, + defaultSystem.zosmf.user, + defaultSystem.zosmf.password, + defaultSystem.zosmf.rejectUnauthorized, + ussnameAsTxt, + __dirname + + `/__resources__/${ + binary + ? ".zosattributes" + : ".zosattributes-binary" + }`, + ] + ); + } catch (err) { + error = err; + } + + expect(error).toBeFalsy(); + expect(response).toBeTruthy(); + expect(downloadResponse).toBeTruthy(); + + // Compare the downloaded contents to those uploaded + const fileContents = fs + .readFileSync( + `${testEnvironment.workingDir}/${posix.basename( + ussnameAsTxt + )}` + ) + .toString(); + expect(fileContents).toEqual( + fs + .readFileSync( + __dirname + + "/__resources__/testfiles/" + + uploadFile + ) + .toString() + ); + }); + } + ); // When requesting etag, z/OSMF has a limit on file size when it stops to return etag by default (>8mb) // We are passing X-IBM-Return-Etag to force z/OSMF to always return etag, but testing here for case where it would be optional it("should download a 10mb uss file and return Etag", async () => { diff --git a/packages/zosfiles/__tests__/__unit__/methods/download/Download.unit.test.ts b/packages/zosfiles/__tests__/__unit__/methods/download/Download.unit.test.ts index 6a0393efd2..ce404abc48 100644 --- a/packages/zosfiles/__tests__/__unit__/methods/download/Download.unit.test.ts +++ b/packages/zosfiles/__tests__/__unit__/methods/download/Download.unit.test.ts @@ -2214,7 +2214,7 @@ describe("z/OS Files - Download", () => { expect(zosmfGetFullSpy).toHaveBeenCalledTimes(1); expect(zosmfGetFullSpy).toHaveBeenCalledWith(dummySession, { resource: endpoint, - reqHeaders: [{ "X-IBM-Data-Type": "text;fileEncoding=IBM-1047" }, ZosmfHeaders.ACCEPT_ENCODING, ZosmfHeaders.TEXT_PLAIN], + reqHeaders: [{ "X-IBM-Data-Type": "text;fileEncoding=IBM-1047" }, ZosmfHeaders.ACCEPT_ENCODING, {"Content-Type": "UTF-8"}], responseStream: fakeStream, normalizeResponseNewLines: true, task: undefined /* no progress task */ diff --git a/packages/zosfiles/src/methods/download/Download.ts b/packages/zosfiles/src/methods/download/Download.ts index db2a682a64..ba7a5ede5e 100644 --- a/packages/zosfiles/src/methods/download/Download.ts +++ b/packages/zosfiles/src/methods/download/Download.ts @@ -523,10 +523,8 @@ export class Download { if(options.attributes) { - options.binary = options.attributes.getFileTransferMode(ussFileName, options.binary) === TransferMode.BINARY; - const remoteEncoding = options.attributes.getRemoteEncoding(ussFileName); - if(remoteEncoding === Tag.BINARY) options.encoding = undefined; - else if(remoteEncoding !== null) options.encoding = remoteEncoding; + options = { ...options, ...this.parseAttributeOptions(ussFileName,options)} + if(options.binary) options.encoding = undefined; } // If data type is not defined by user via encoding flag or attributes file, check for USS tags