support for s3 and minio

This commit is contained in:
2021-11-18 19:16:44 +01:00
parent 63e801ad05
commit c05ee888eb
10 changed files with 604 additions and 21 deletions

View File

@@ -1,7 +1,6 @@
import { createHash } from 'crypto'
import { validateSync, ValidatorOptions, ValidationError as VE } from 'class-validator'
import { PassThrough, Readable } from 'stream'
import { NullableStringOrRegexpArray } from '../config'
export class ValidationError extends Error {
override message: string
@@ -47,3 +46,21 @@ export function testForPrefixOrRegexp(str: string, values: (string | RegExp)[]):
}
return false
}
export class StreamUtils {
static fromBuffer(buffer: Buffer) {
const stream = new Readable()
stream.push(buffer)
stream.push(null)
return stream
}
static toBuffer(stream: NodeJS.ReadableStream) {
return new Promise<Buffer>((resolve, reject) => {
const chunks: Buffer[] = []
stream.on('data', (chunk) => chunks.push(chunk))
stream.on('error', reject)
stream.on('end', () => resolve(Buffer.concat(chunks)))
})
}
}