mirror of
https://github.com/cupcakearmy/morphus.git
synced 2025-09-07 16:40:39 +00:00
progress
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
import { Config, StorageType } from '../config'
|
||||
import { Local } from './local'
|
||||
|
||||
export interface Storage {
|
||||
read(path: string): Promise<Buffer>
|
||||
write(path: string, data: Buffer): Promise<void>
|
||||
exists(path: string): Promise<boolean>
|
||||
delete(path: string): Promise<void>
|
||||
export abstract class Storage {
|
||||
abstract read(path: string): Promise<Buffer>
|
||||
abstract write(path: string, data: Buffer): Promise<void>
|
||||
abstract exists(path: string): Promise<boolean>
|
||||
abstract delete(path: string): Promise<void>
|
||||
|
||||
readStream(path: string): Promise<NodeJS.ReadableStream>
|
||||
writeStream(path: string): Promise<NodeJS.WritableStream>
|
||||
abstract readStream(path: string): Promise<NodeJS.ReadableStream>
|
||||
abstract writeStream(path: string): Promise<NodeJS.WritableStream>
|
||||
// list(path: string): Promise<string[]>
|
||||
|
||||
abstract init(): Promise<void>
|
||||
}
|
||||
|
||||
export let storage: Storage
|
||||
|
||||
export function init() {
|
||||
export async function init() {
|
||||
if (!storage) {
|
||||
switch (Config.storage) {
|
||||
case StorageType.Local:
|
||||
@@ -23,5 +25,6 @@ export function init() {
|
||||
default:
|
||||
throw new Error(`Unknown storage type: ${Config.storage}`)
|
||||
}
|
||||
await storage.init()
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { resolve, join } from 'path'
|
||||
import fs from 'fs'
|
||||
import { promisify } from 'util'
|
||||
|
||||
import { Storage } from './'
|
||||
|
||||
@@ -8,6 +9,10 @@ export class Local implements Storage {
|
||||
this.root = resolve(root)
|
||||
}
|
||||
|
||||
async init() {
|
||||
await promisify(fs.mkdir)(this.root, { recursive: true })
|
||||
}
|
||||
|
||||
read(path: string): Promise<Buffer> {
|
||||
const file = join(this.root, path)
|
||||
return new Promise((resolve, reject) => {
|
||||
|
Reference in New Issue
Block a user