import { posix } from "path" ; import { AbstractSession , ImperativeExpect } from "@zowe/imperative" ; import { ZosFilesMessages } from "../../constants/ZosFiles.messages" ; import { ZosFilesConstants } from "../../constants/ZosFiles.constants" ; import { ZosmfRestClient , ZosmfHeaders , IHeaderContent } from "@zowe/core-for-zowe-sdk" ; import { IGetOptions } from "./doc/IGetOptions" ; import { ZosFilesUtils } from "../../utils/ZosFilesUtils" ; export class export class Get { param { AbstractSession } session param { string } dataSetName param { IViewOptions } options returns { Promise < Buffer > } throws public static async dataSet ( session , dataSetName , options = { } ) { ImperativeExpect . toNotBeNullOrUndefined ( dataSetName , ZosFilesMessages . missingDatasetName . message ) ; ImperativeExpect . toNotBeEqual ( dataSetName , "" , ZosFilesMessages . missingDatasetName . message ) ; let endpoint = posix . join ( ZosFilesConstants . RESOURCE , ZosFilesConstants . RES_DS_FILES , dataSetName ) ; const reqHeaders = ZosFilesUtils . generateHeadersBasedOnOptions ( options ) ; if ( options . volume ) { endpoint = posix . join ( ZosFilesConstants . RESOURCE , ZosFilesConstants . RES_DS_FILES , `-(${ options . volume })` , dataSetName ) ; } const content = await ZosmfRestClient . getExpectBuffer ( session , endpoint , reqHeaders ) ; return content ; } param { AbstractSession } session param { string } USSFileName param { IViewOptions } options returns { Promise < Buffer > } throws public static async USSFile ( session , USSFileName , options = { } ) { ImperativeExpect . toNotBeNullOrUndefined ( USSFileName , ZosFilesMessages . missingUSSFileName . message ) ; ImperativeExpect . toNotBeEqual ( USSFileName , "" , ZosFilesMessages . missingUSSFileName . message ) ; USSFileName = posix . normalize ( USSFileName ) ; if ( USSFileName . substr ( 0 , 1 ) === "/" ) { USSFileName = USSFileName . substr ( 1 ) ; } const encodedFileName = encodeURIComponent ( USSFileName ) ; const endpoint = posix . join ( ZosFilesConstants . RESOURCE , ZosFilesConstants . RES_USS_FILES , encodedFileName ) ; const reqHeaders = [ ZosmfHeaders . ACCEPT_ENCODING ] ; if ( options . binary === true ) { reqHeaders . unshift ( ZosmfHeaders . X_IBM_BINARY ) ; } const content = await ZosmfRestClient . getExpectBuffer ( session , endpoint , reqHeaders ) ; return content ; } }