Files
Xen-Orchestra-xen-orchestra…/@xen-orchestra/vmware-explorer/DatastoreSoapEsxi.mjs
Florent BEAUCHAMP 8756d12b8b fix(vmware-explorer): correctly handle stream and buffer
following dependence update 34e8ff6bae
2025-04-29 10:17:28 +02:00

24 lines
895 B
JavaScript

import { Datastore } from './_Datastore.mjs'
import { Readable } from 'node:stream'
export class DatastoreSoapEsxi extends Datastore {
#esxi
constructor(datastoreName, { esxi, ...otherOptions } = {}) {
super(datastoreName, otherOptions)
this.#esxi = esxi
}
async getStream(path, start, end) {
const res = await this.#esxi.download(this.datastoreName, path, start || end ? `${start}-${end}` : undefined)
return Readable.from(res.body, { objectMode: false, highWaterMark: 2 * 1024 * 1024 })
}
async getBuffer(path, start, end) {
const res = await this.#esxi.download(this.datastoreName, path, start || end ? `${start}-${end - 1}` : undefined)
const bytes = await res.bytes()
return Buffer.from(bytes)
}
async getSize(path) {
const res = await this.#esxi.download(this.datastoreName, path)
return Number(res.headers.get('content-length'))
}
}