mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-11-09 17:06:13 -06:00
24 lines
895 B
JavaScript
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'))
|
|
}
|
|
}
|