You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
662 B

import { FastifyRequest } from 'fastify'
import concat = require('concat-stream')
import { StorageEngine, File } from '../interfaces'
class MemoryStorage implements StorageEngine {
_handleFile(
_req: FastifyRequest,
file: File,
cb: (error: Error | null, info?: Partial<File>) => void,
): void {
file.stream!.pipe(
concat({ encoding: 'buffer' }, function(data) {
cb(null, {
buffer: data,
size: data.length,
})
}),
)
}
_removeFile(_req: FastifyRequest, file: File, cb: (error?: Error) => void) {
delete file.buffer
cb(undefined)
}
}
export default () => new MemoryStorage()