mobiletto 1.0.35 → 1.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/drivers/local/index.js +17 -3
- package/drivers/s3/index.js +15 -1
- package/index.js +19 -3
- package/package.json +1 -1
- package/test/index.spec.js +7 -2
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Mobiletto is a JavaScript storage abstraction layer, with optional transparent c
|
|
|
5
5
|
|
|
6
6
|
It supports apps that are agnostic to where files are stored.
|
|
7
7
|
|
|
8
|
-
All drivers are tested for identical behavior with over
|
|
8
|
+
All drivers are tested for identical behavior with over 50 tests for each driver.
|
|
9
9
|
|
|
10
10
|
Today the supported drivers are:
|
|
11
11
|
|
package/drivers/local/index.js
CHANGED
|
@@ -112,8 +112,8 @@ class StorageClient {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
async list (
|
|
116
|
-
const dir = this.normalizePath(
|
|
115
|
+
async list (pth = '', recursive = false, visitor = null) {
|
|
116
|
+
const dir = this.normalizePath(pth)
|
|
117
117
|
try {
|
|
118
118
|
if (visitor === null) {
|
|
119
119
|
const results = []
|
|
@@ -123,7 +123,21 @@ class StorageClient {
|
|
|
123
123
|
return await this.readDirFiles(dir, recursive, visitor)
|
|
124
124
|
}
|
|
125
125
|
} catch (err) {
|
|
126
|
-
|
|
126
|
+
if (err instanceof MobilettoNotFoundError && !recursive && pth.includes('/')) {
|
|
127
|
+
// are we trying to list a single file?
|
|
128
|
+
const parentDir = this.normalizePath(dirname(pth))
|
|
129
|
+
const results = []
|
|
130
|
+
await this.readDirFiles(parentDir, false, (obj) => {
|
|
131
|
+
if (obj.name === pth) {
|
|
132
|
+
results.push(obj)
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
if (results.length === 0) {
|
|
136
|
+
throw err
|
|
137
|
+
}
|
|
138
|
+
return results
|
|
139
|
+
}
|
|
140
|
+
throw this.ioError(err, pth, 'list')
|
|
127
141
|
}
|
|
128
142
|
}
|
|
129
143
|
async metadata (path) {
|
package/drivers/s3/index.js
CHANGED
|
@@ -3,6 +3,8 @@ const {
|
|
|
3
3
|
MobilettoError, MobilettoNotFoundError, readStream
|
|
4
4
|
} = require('../../index')
|
|
5
5
|
|
|
6
|
+
const { dirname } = require('path')
|
|
7
|
+
|
|
6
8
|
const {
|
|
7
9
|
S3Client,
|
|
8
10
|
ListObjectsCommand,
|
|
@@ -57,7 +59,19 @@ class StorageClient {
|
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
async list (path = '', recursive = false, visitor = null) {
|
|
60
|
-
|
|
62
|
+
try {
|
|
63
|
+
return await this._list(path, recursive, visitor)
|
|
64
|
+
} catch (e) {
|
|
65
|
+
if (e instanceof MobilettoNotFoundError && !recursive && path.includes('/')) {
|
|
66
|
+
// are we trying to list a single file?
|
|
67
|
+
const objects = await this._list(dirname(path), false)
|
|
68
|
+
const found = objects.find(o => o.name === path)
|
|
69
|
+
if (found) {
|
|
70
|
+
return [found]
|
|
71
|
+
}
|
|
72
|
+
throw e
|
|
73
|
+
}
|
|
74
|
+
}
|
|
61
75
|
}
|
|
62
76
|
|
|
63
77
|
async _list (path, recursive = false, visitor = null, params = {}) {
|
package/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
2
3
|
const winston = require('winston')
|
|
3
4
|
const LRU = require('lru-cache')
|
|
4
5
|
const { basename, dirname } = require('path')
|
|
@@ -347,9 +348,24 @@ async function mobiletto (driverPath, key, secret, opts, encryption = null) {
|
|
|
347
348
|
}
|
|
348
349
|
|
|
349
350
|
const encClient = {
|
|
350
|
-
list: async (
|
|
351
|
-
const dirent = direntDir(
|
|
352
|
-
|
|
351
|
+
list: async (pth, recursive, visitor) => {
|
|
352
|
+
const dirent = direntDir(pth)
|
|
353
|
+
let entries
|
|
354
|
+
try {
|
|
355
|
+
entries = await client.list(dirent, recursive)
|
|
356
|
+
} catch (e) {
|
|
357
|
+
if (e instanceof MobilettoNotFoundError) {
|
|
358
|
+
// it might be a single file, try listing the parent dir
|
|
359
|
+
const parentDirent = direntDir(path.dirname(pth));
|
|
360
|
+
entries = await client.list(parentDirent, false)
|
|
361
|
+
const objects = await _loadMeta(parentDirent, entries)
|
|
362
|
+
const found = objects.find(o => o.name === pth)
|
|
363
|
+
if (found) {
|
|
364
|
+
return [ found ]
|
|
365
|
+
}
|
|
366
|
+
throw e
|
|
367
|
+
}
|
|
368
|
+
}
|
|
353
369
|
if (!entries || entries.length === 0) {
|
|
354
370
|
return []
|
|
355
371
|
}
|
package/package.json
CHANGED
package/test/index.spec.js
CHANGED
|
@@ -149,7 +149,7 @@ for (const driverName of DRIVER_NAMES) {
|
|
|
149
149
|
it("should read the file we just wrote", async () => {
|
|
150
150
|
const data = await fixture.api.readFile(fixture.name);
|
|
151
151
|
expect(data.length).is.equal(size, 'expected read API to return correct number of bytes read')
|
|
152
|
-
expect(data.toString(
|
|
152
|
+
expect(data.toString()).to.equal(fixture.randomData, 'expected to read back the same data we wrote')
|
|
153
153
|
})
|
|
154
154
|
it("should load metadata on the file we just wrote", async () => {
|
|
155
155
|
await assertMeta (fixture.api, fixture.name, fixture.randomData.length)
|
|
@@ -253,7 +253,7 @@ for (const driverName of DRIVER_NAMES) {
|
|
|
253
253
|
const mirrorDest = `mirrorDest_${rand(5)}/`
|
|
254
254
|
describe(`${driverName} - ${encDesc} write files in a new dir, read metadata, mirror to another place (${mirrorDriver}), verify mirror, recursively delete from both`, () => {
|
|
255
255
|
// describe(`${driverName} - ENCRYPTION write files in a new dir, read metadata, recursively delete`, () => {
|
|
256
|
-
|
|
256
|
+
// const encryption = {key: rand(32)}
|
|
257
257
|
// const encryption = null
|
|
258
258
|
// a random directory and file within it
|
|
259
259
|
const randomParent = `testRPD_${rand(2)}/rand_${rand(4)}`
|
|
@@ -300,6 +300,11 @@ for (const driverName of DRIVER_NAMES) {
|
|
|
300
300
|
const removed = await fixture.api.remove(streamFile)
|
|
301
301
|
expect(!!removed).to.be.true
|
|
302
302
|
})
|
|
303
|
+
it("should successfully list a file individually", async () => {
|
|
304
|
+
const singleFile = await fixture.api.list(fixture.name)
|
|
305
|
+
expect(singleFile).to.have.lengthOf(1)
|
|
306
|
+
expect(singleFile[0]).to.have.property('name', fixture.name)
|
|
307
|
+
})
|
|
303
308
|
it("should load metadata for one of the new files", async () => {
|
|
304
309
|
await assertMeta(fixture.api, fixture.name, READ_SZ, encryption ? ENC_SIZE_CLOSE_ENOUGH_PERCENT : null)
|
|
305
310
|
})
|