diff --git a/packages/blockstore-fs/package.json b/packages/blockstore-fs/package.json index 78abc2ac..87a53f60 100644 --- a/packages/blockstore-fs/package.json +++ b/packages/blockstore-fs/package.json @@ -77,13 +77,13 @@ }, "dependencies": { "blockstore-core": "^4.0.0", - "fast-write-atomic": "^0.2.1", "interface-blockstore": "^5.0.0", "interface-store": "^5.0.0", "it-glob": "^2.0.6", "it-map": "^3.0.5", "it-parallel-batch": "^3.0.4", - "multiformats": "^13.0.1" + "multiformats": "^13.0.1", + "steno": "^4.0.2" }, "devDependencies": { "aegir": "^42.2.3", diff --git a/packages/blockstore-fs/src/index.ts b/packages/blockstore-fs/src/index.ts index 85d47bd9..242a88e5 100644 --- a/packages/blockstore-fs/src/index.ts +++ b/packages/blockstore-fs/src/index.ts @@ -14,33 +14,29 @@ import fs from 'node:fs/promises' import path from 'node:path' -import { promisify } from 'node:util' import { Errors } from 'blockstore-core' -// @ts-expect-error no types -import fwa from 'fast-write-atomic' import glob from 'it-glob' import map from 'it-map' import parallelBatch from 'it-parallel-batch' +import { Writer } from 'steno' import { NextToLast, type ShardingStrategy } from './sharding.js' import type { Blockstore, Pair } from 'interface-blockstore' import type { AwaitIterable } from 'interface-store' import type { CID } from 'multiformats/cid' -const writeAtomic = promisify(fwa) - /** * Write a file atomically */ async function writeFile (file: string, contents: Uint8Array): Promise { try { - await writeAtomic(file, contents) + const writer = new Writer(file) + await writer.write(contents) } catch (err: any) { if (err.syscall === 'rename' && ['ENOENT', 'EPERM'].includes(err.code)) { - // fast-write-atomic writes a file to a temp location before renaming it. - // On Windows, if the final file already exists this error is thrown. - // No such error is thrown on Linux/Mac + // steno writes a file to a temp location before renaming it. + // If the final file already exists this error is thrown. // Make sure we can read & write to this file await fs.access(file, fs.constants.F_OK | fs.constants.W_OK) diff --git a/packages/datastore-fs/package.json b/packages/datastore-fs/package.json index 2cb1d12b..72502e77 100644 --- a/packages/datastore-fs/package.json +++ b/packages/datastore-fs/package.json @@ -56,12 +56,12 @@ }, "dependencies": { "datastore-core": "^9.0.0", - "fast-write-atomic": "^0.2.1", "interface-datastore": "^8.0.0", "interface-store": "^5.0.0", "it-glob": "^2.0.6", "it-map": "^3.0.5", - "it-parallel-batch": "^3.0.4" + "it-parallel-batch": "^3.0.4", + "steno": "^4.0.2" }, "devDependencies": { "@types/mkdirp": "^2.0.0", diff --git a/packages/datastore-fs/src/index.ts b/packages/datastore-fs/src/index.ts index fa771408..c2eff371 100644 --- a/packages/datastore-fs/src/index.ts +++ b/packages/datastore-fs/src/index.ts @@ -14,33 +14,29 @@ import fs from 'node:fs/promises' import path from 'node:path' -import { promisify } from 'util' import { BaseDatastore, Errors } from 'datastore-core' -// @ts-expect-error no types -import fwa from 'fast-write-atomic' import { Key, type KeyQuery, type Pair, type Query } from 'interface-datastore' import glob from 'it-glob' import map from 'it-map' import parallel from 'it-parallel-batch' +import { Writer } from 'steno' import type { AwaitIterable } from 'interface-store' -const writeAtomic = promisify(fwa) - /** * Write a file atomically */ async function writeFile (path: string, contents: Uint8Array): Promise { try { - await writeAtomic(path, contents) + const writer = new Writer(path) + await writer.write(contents) } catch (err: any) { if (err.syscall === 'rename' && ['ENOENT', 'EPERM'].includes(err.code)) { - // fast-write-atomic writes a file to a temp location before renaming it. - // On Windows, if the final file already exists this error is thrown. - // No such error is thrown on Linux/Mac + // steno writes a file to a temp location before renaming it. + // If the final file already exists this error is thrown. // Make sure we can read & write to this file await fs.access(path, fs.constants.F_OK | fs.constants.W_OK)