-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat! embrace writable streams (#29)
- Loading branch information
Showing
22 changed files
with
954 additions
and
867 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,103 @@ | ||
import * as UnixFS from "./unixfs.js" | ||
import type { | ||
WriterConfig, | ||
EncoderConfig, | ||
FileWriter, | ||
WriterOptions, | ||
EncoderSettings, | ||
WritableBlockStream, | ||
BlockWriter, | ||
View as FileWriterView, | ||
Writer as FileWriter, | ||
Options as FileWriterOptions, | ||
State as FileWriterSate, | ||
CloseOptions, | ||
Chunker, | ||
LayoutEngine, | ||
Block, | ||
MultihashHasher, | ||
MultihashDigest, | ||
EncodedFile, | ||
} from "./file.js" | ||
import type { DirectoryWriter } from "./directory.js" | ||
|
||
export type { Channel, Writer } from "./writer/channel.js" | ||
import type { | ||
DirectoryEntry, | ||
Writer as DirectoryWriter, | ||
View as DirectoryWriterView, | ||
Options as DirectoryWriterOptions, | ||
State as DirectoryWriterState, | ||
} from "./directory.js" | ||
import { Metadata } from "./unixfs.js" | ||
|
||
export type { | ||
WriterConfig, | ||
EncoderConfig, | ||
WriterOptions, | ||
CloseOptions, | ||
EncoderSettings, | ||
FileWriterOptions, | ||
FileWriterView, | ||
FileWriter, | ||
FileWriterSate, | ||
EncodedFile, | ||
BlockWriter, | ||
FileWriterConfig, | ||
WritableBlockStream, | ||
} from "./file/api.js" | ||
export { | ||
DirectoryWriterView, | ||
DirectoryWriter, | ||
DirectoryWriterOptions, | ||
DirectoryWriterState, | ||
DirectoryEntry, | ||
DirectoryConfig, | ||
} from "./directory/api.js" | ||
Chunker, | ||
LayoutEngine, | ||
Block, | ||
MultihashHasher, | ||
MultihashDigest, | ||
Metadata, | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
export interface Writer { | ||
/** | ||
* Closes this writer and corresponding | ||
*/ | ||
close(options?: CloseOptions): Promise<this> | ||
} | ||
|
||
/** | ||
* Represents an IPLD [block][] channel with `reader` and `writer` halves. The | ||
* `writer` half provides filesystem like interface for encoding files & | ||
* directories into a [UnixFS][] DAG. The `reader` half emits all the IPLD | ||
* [blocks][] that are created in the process. | ||
* Represents [UnixFS][] DAG writer with a filesystem like API for | ||
* encoding files & directories into a [UnixFS][] DAG. | ||
* | ||
* [block]:https://ipld.io/docs/intro/primer/#blocks-vs-nodes | ||
* [UnixFS]:https://github.com/ipfs/specs/blob/main/UNIXFS.md | ||
*/ | ||
export interface FileSystem<Layout extends unknown = unknown> | ||
extends FileSystemWriter<Layout> { | ||
readonly readable: ReadableStream<UnixFS.Block> | ||
|
||
readonly writable: WritableBlockStream | ||
export interface View<L extends unknown = unknown> extends Writer { | ||
/** | ||
* Underlaying stream where [UnixFS][] blocks will be written into. | ||
*/ | ||
readonly writer: BlockWriter | ||
/** | ||
* Encoder configuration of this writer. | ||
*/ | ||
|
||
blocks: AsyncIterableIterator<UnixFS.Block> | ||
} | ||
readonly settings: EncoderSettings<L> | ||
|
||
export interface FileSystemWriter<L extends unknown = unknown> | ||
extends FileSystemConfig<L> { | ||
/** | ||
* Creates new file writer that will write blocks into the same `BlockQueue` | ||
* as this `DirectoryWriter`. | ||
* | ||
* ⚠️ Please note that file represented by the returned writer is not added to | ||
* to this directory, you need to do that explicitly via `write` call. | ||
* Creates new file writer that will write blocks into the same underlying | ||
* stream. It is mostly convinience function for passing same stream and | ||
* encoder configuration. | ||
*/ | ||
createFileWriter<Layout>( | ||
options?: WriterConfig<Layout> | ||
): FileWriter<L | Layout> | ||
settings?: WriterOptions<Layout> | ||
): FileWriterView<L | Layout> | ||
|
||
/** | ||
* Creates new directory writer that will write blocks into the same | ||
* `BlockQueue` as this `DirectoryWriter`. | ||
* | ||
* * ⚠️ Please note that directory represented by returned writer is not | ||
* added to this directory, you need to do that explicitly via `write` call. | ||
* underlying stream as this writer. It is mostly convinienc function for | ||
* passing same stream and encoder configuration. | ||
* | ||
*/ | ||
createDirectoryWriter(options?: WriterConfig): DirectoryWriter | ||
|
||
close(): Promise<void> | ||
createDirectoryWriter<Layout>( | ||
settings?: WriterOptions<Layout> | ||
): DirectoryWriterView<L | Layout> | ||
} | ||
|
||
export interface FileSystemConfig<Layout extends unknown = unknown> { | ||
export interface Options<Layout extends unknown = unknown> { | ||
writable: WritableBlockStream | ||
config?: EncoderConfig<Layout> | ||
settings?: EncoderSettings<Layout> | ||
} |
Oops, something went wrong.