forked from max-mapper/google-cloud-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMockStorage.ts
29 lines (27 loc) · 874 Bytes
/
MockStorage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Mem, { ExistsCallback, RemoveCallback } from "abstract-blob-store";
const noop = () => {};
export class MockStorage {
private store = new Mem();
get metadata() {
return this.store;
}
bucket() {
const { store } = this;
return {
file: (key: string) => ({
createWriteStream: () => store.createWriteStream({ key }, noop),
createReadStream: () => store.createReadStream({ key }),
get: (cb1: Function) =>
store.exists({ key }, (_, ex) =>
ex
? cb1(null, {
createReadStream: () => store.createReadStream({ key }),
})
: cb1("Not found")
),
exists: (cb2: ExistsCallback) => store.exists({ key }, cb2),
delete: (cb3: RemoveCallback) => store.remove({ key }, cb3),
}),
};
}
}