Class: FileStore
Defined in: src/file-store.ts:15
A verified content-addressed file store.
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files')
const stored = store.put(Buffer.from('data'))Constructors
new FileStore(
basePath,readOnly?):FileStore
Defined in: src/file-store.ts:16
Parameters
| Parameter | Type | Default value |
|---|---|---|
basePath | string | undefined |
readOnly | boolean | false |
Returns
FileStore
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files')
return storeMethods
beginTransaction()
beginTransaction():
FileStoreTransaction
Defined in: src/file-store.ts:87
Starts a temporary file transaction for a compound operation.
Returns
FileStoreTransaction
A transaction that must be committed and finalised by its owner.
See
FileStoreTransaction
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files')
const transaction = store.beginTransaction()
transaction.rollback()
return transactionhasPath()
hasPath(
hash):boolean
Defined in: src/file-store.ts:135
Checks for a stored path without hashing its contents.
Parameters
| Parameter | Type |
|---|---|
hash | string |
Returns
boolean
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files')
const stored = store.put(Buffer.from('data'))
return store.hasPath(stored.hash)path()
path(
hash):string
Defined in: src/file-store.ts:24
Returns the canonical path for a SHA-256 file hash.
Parameters
| Parameter | Type |
|---|---|
hash | string |
Returns
string
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files')
return store.path('a'.repeat(64))promote()
promote(
temporary,hash):string
Defined in: src/file-store.ts:162
Parameters
| Parameter | Type |
|---|---|
temporary | string |
hash | string |
Returns
string
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files')
const hash = 'a'.repeat(64)
const temporary = store.temporaryPath(hash)
return store.promote(temporary, hash)put()
put(
content,expectedHash?):object
Defined in: src/file-store.ts:44
Stores content after checking or calculating its SHA-256 hash.
Parameters
| Parameter | Type |
|---|---|
content | Buffer |
expectedHash? | string |
Returns
object
created
created:
boolean
hash
hash:
string
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files')
const content = Buffer.from('data')
const stored = store.put(content)
return stored.hashputFile()
putFile(
source,hash):object
Defined in: src/file-store.ts:72
Promotes an already hashed temporary file without buffering it.
Parameters
| Parameter | Type |
|---|---|
source | string |
hash | string |
Returns
object
created
created:
boolean
hash
hash:
string
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files')
const hash = 'a'.repeat(64)
const temporary = store.temporaryPath(hash)
return store.putFile(temporary, hash)read()
read(
hash,verify?):Buffer
Defined in: src/file-store.ts:106
Reads a file and optionally verifies its content hash.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
hash | string | undefined | SHA-256 content address. |
verify | boolean | true | Recompute the hash before returning. |
Returns
Buffer
The stored file contents.
Default
trueThrows
If the file is missing, invalid, or fails verification.
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files', true)
const hash = 'a'.repeat(64)
const content = store.read(hash)
return content.lengthrecoveryBasePath()
recoveryBasePath():
string
Defined in: src/file-store.ts:30
Returns the resolved root used by transaction recovery.
Returns
string
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files')
return store.recoveryBasePath()remove()
remove(
hash):boolean
Defined in: src/file-store.ts:144
Removes a stored file after checking that the session is writable.
Parameters
| Parameter | Type | Description |
|---|---|---|
hash | string | SHA-256 content address. |
Returns
boolean
Whether a file was removed.
Throws
If the store is read-only or the hash is invalid.
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files')
const stored = store.put(Buffer.from('data'))
return store.remove(stored.hash)temporaryPath()
temporaryPath(
hash):string
Defined in: src/file-store.ts:184
Parameters
| Parameter | Type |
|---|---|
hash | string |
Returns
string
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files')
return store.temporaryPath('a'.repeat(64))verify()
verify(
hash):boolean
Defined in: src/file-store.ts:125
Verifies a stored file without returning its content.
Parameters
| Parameter | Type | Description |
|---|---|---|
hash | string | SHA-256 content address. |
Returns
boolean
true only when the file exists and matches its address.
This example requires Node.js.
import { FileStore } from 'osu-files'
const store = new FileStore('./files', true)
const hash = 'a'.repeat(64)
return store.verify(hash)