packageDocumentation module import * as fs from "fs-extra" ; import * as https from "https" ; import * as pathLib from "path" ; import * as url from "url" ; import { AccessToken , Logger } from "@itwin/core-bentley" ; import { ProgressCallback } from "./Request" ; import { FileHandler } from "../itwin-client/FileHandler" ; import { IModelHubClientLoggerCategory } from "../IModelHubClientLoggerCategories" ; const loggerCategory = IModelHubClientLoggerCategory . FileHandlers ; internal export class LocalhostHandler implements FileHandler { public agent ? : https . Agent ; param downloadUrl param path param fileSize param progressCallback public async downloadFile ( _accessToken , downloadUrl , path , fileSize ? , progress ? ) { Logger . logTrace ( loggerCategory , `Downloading file from '${ downloadUrl }' to '${ path }'.` ) ; await fs . ensureDir ( pathLib . dirname ( path ) ) ; await fs . copy ( url . fileURLToPath ( downloadUrl ) , path ) ; if ( progress ) { const size = fileSize || this . getFileSize ( path ) ; progress ( { loaded : size , total : size , percent : 100 } ) ; } } param uploadUrl param path param progressCallback public async uploadFile ( _accessToken , uploadUrlString , path , progress ? ) { Logger . logTrace ( loggerCategory , `Uploading file '${ path }' to '${ uploadUrlString }'.` ) ; const uploadPath = url . fileURLToPath ( uploadUrlString ) ; await fs . ensureDir ( pathLib . dirname ( uploadPath ) ) ; await fs . copy ( path , uploadPath ) ; if ( progress ) { const fileSize = this . getFileSize ( path ) ; progress ( { loaded : fileSize , total : fileSize , percent : 100 } ) ; } } param filePath returns public getFileSize ( filePath ) { return fs . statSync ( filePath ) . size ; } param filePath returns public isDirectory ( filePath ) { return fs . statSync ( filePath ) . isDirectory ( ) ; } param filePath returns public exists ( filePath ) { return fs . existsSync ( filePath ) ; } param filePath public unlink ( filePath ) { fs . unlinkSync ( filePath ) ; } param filePath returns public basename ( filePath ) { return pathLib . basename ( filePath ) ; } param paths returns public join ( ... paths ) { return pathLib . join ( ... paths ) ; } }