@ocfl/ocfl-fs 0.1.0
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 +4 -0
- package/index.js +10 -0
- package/index.mjs +3 -0
- package/lib/store.js +106 -0
- package/lib/types.d.ts +3 -0
- package/lib/utils.js +0 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# ocfl-js - Filesystem storage implementation
|
|
2
|
+
This is JavaScript/Node.js library to create and interact with Oxford Common File Layout (OCFL) storage and objects within it.
|
|
3
|
+
This package implements the OCFL client that stores storage root and its objects on a locally attached filesystem.
|
|
4
|
+
|
package/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
const { OcflFsStore } = require('./lib/store.js');
|
|
3
|
+
const { Ocfl } = require('ocfl');
|
|
4
|
+
//const { default: ocfl } = require('./index.mjs');
|
|
5
|
+
|
|
6
|
+
/** @type {import('./lib/store.js').OcflFsStoreConfig} */
|
|
7
|
+
let defaultOptions;
|
|
8
|
+
|
|
9
|
+
module.exports = new Ocfl(OcflFsStore, defaultOptions);
|
|
10
|
+
//module.exports.default = module.exports;
|
package/index.mjs
ADDED
package/lib/store.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const { mkdir, copyFile, rename, unlink } = fs.promises;
|
|
5
|
+
|
|
6
|
+
const { OcflStore, OcflConstants } = require('ocfl');
|
|
7
|
+
const { INVENTORY_NAME } = OcflConstants;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {Object} OcflFsStoreConfig
|
|
11
|
+
* @property {typeof fs} [fs] - Custom fs module to use for any file operation
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* OCFL Object backed by local filesystem
|
|
16
|
+
*/
|
|
17
|
+
class OcflFsStore extends OcflStore {
|
|
18
|
+
/** @type {Map<Object, OcflFsStore>} */
|
|
19
|
+
static instances = new Map();
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} options
|
|
24
|
+
* @param {typeof fs} [options.fs]
|
|
25
|
+
*/
|
|
26
|
+
// static getInstance({fs = require('fs')} = {}) {
|
|
27
|
+
// let store = OcflFsStore.instances.get(fs);
|
|
28
|
+
// if (!store) {
|
|
29
|
+
// store = new OcflFsStore({fs});
|
|
30
|
+
// OcflFsStore.instances.set(fs, store);
|
|
31
|
+
// }
|
|
32
|
+
// return store;
|
|
33
|
+
// }
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create a new backend store that uses the given fs api.
|
|
37
|
+
* A typical use case would be a locally mounted file system.
|
|
38
|
+
* @param {OcflFsStoreConfig} [config]
|
|
39
|
+
*/
|
|
40
|
+
constructor(config) {
|
|
41
|
+
super();
|
|
42
|
+
this.fs = config?.fs ?? fs;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async stat(filePath) {
|
|
46
|
+
return this.fs.promises.stat(filePath);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async createReadStream(filePath, options) {
|
|
50
|
+
await this.fs.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
51
|
+
return this.fs.createReadStream(filePath, options);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async createWriteStream(filePath, options) {
|
|
55
|
+
await this.fs.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
56
|
+
return this.fs.createWriteStream(filePath, options);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async readFile(filePath, options) {
|
|
60
|
+
return this.fs.promises.readFile(filePath, options);
|
|
61
|
+
//if (err.code !== 'ENOENT') throw validation.createError(34, invPath);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async writeFile(filePath, data, options) {
|
|
65
|
+
await this.fs.promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
66
|
+
await this.fs.promises.writeFile(filePath, data, options);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async copyFile(source, target) {
|
|
70
|
+
await this.fs.promises.mkdir(path.dirname(target), { recursive: true });
|
|
71
|
+
await this.fs.promises.copyFile(source, target);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async opendir(filePath, options) {
|
|
75
|
+
return this.fs.promises.opendir(filePath, options);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async readdir(filePath, options) {
|
|
79
|
+
return this.fs.promises.readdir(filePath, options);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async mkdir(filePath, options = { recursive: true }) {
|
|
83
|
+
return this.fs.promises.mkdir(filePath, options);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async move(source, target) {
|
|
87
|
+
try {
|
|
88
|
+
return this.fs.promises.rename(source, target);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (error.code === 'EXDEV') {
|
|
91
|
+
await this.fs.promises.cp(source, path.dirname(target), { recursive: true, preserveTimestamps: true });
|
|
92
|
+
return this.fs.promises.rm(target, { recursive: true, force: true });
|
|
93
|
+
} else {
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async remove(filePath) {
|
|
100
|
+
return this.fs.promises.rm(filePath, { recursive: true, force: true });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
module.exports = { OcflFsStore };
|
package/lib/types.d.ts
ADDED
package/lib/utils.js
ADDED
|
File without changes
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ocfl/ocfl-fs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Oxford Common File Layout (OCFL) JS client library for filesystem storage",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": [
|
|
8
|
+
{
|
|
9
|
+
"import": "./index.mjs",
|
|
10
|
+
"require": "./index.js",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
},
|
|
13
|
+
"./index.js"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "mocha",
|
|
18
|
+
"build-docs2": "typedoc --tsconfig tsconfig.json",
|
|
19
|
+
"build-docs": "jsdoc -c jsdoc.json"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"ocfl",
|
|
23
|
+
"Oxford Common File Layout",
|
|
24
|
+
"preservation",
|
|
25
|
+
"storage",
|
|
26
|
+
"filesystem"
|
|
27
|
+
],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/Arkisto-Platform/ocfl-js"
|
|
31
|
+
},
|
|
32
|
+
"author": "Alvin Sebastian (https://orcid.org/0000-0002-9086-1722)",
|
|
33
|
+
"contributors": [
|
|
34
|
+
"Moises Sacal Bonequi (https://orcid.org/0000-0002-4438-2755)",
|
|
35
|
+
"Peter Sefton (https://orcid.org/0000-0002-3545-944X)"
|
|
36
|
+
],
|
|
37
|
+
"license": "GPL-3.0-or-later",
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/fs-extra": "^9.0.13",
|
|
40
|
+
"clean-jsdoc-theme": "^3.3.4",
|
|
41
|
+
"jsdoc": "^3.6.10",
|
|
42
|
+
"mocha": "^10.0.0",
|
|
43
|
+
"typedoc": "^0.22.15",
|
|
44
|
+
"@ocfl/ocfl-tests": "0.1.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@ocfl/ocfl": "0.1.0"
|
|
48
|
+
},
|
|
49
|
+
"files": [ "index.js", "index.mjs", "lib" ]
|
|
50
|
+
}
|