deferred

package
v2.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2023 License: Apache-2.0, MIT Imports: 10 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeferredCarWriter

type DeferredCarWriter struct {
	// contains filtered or unexported fields
}

DeferredCarWriter creates a write-only CAR either to an existing stream or to a file designated by a supplied path. CAR content (including header) only begins when the first Put() operation is performed. If the output is a file, it will be created when the first Put() operation is performed. DeferredCarWriter is threadsafe, and can be used concurrently. Closing the writer will close, but not delete, the underlying file.

DeferredCarWriter only implements the storage.WritableStorage interface and is not intended as a general purpose storage implementation. It only supports storage Put() and Get() operations.

This utility is useful for cases where a CAR will be streamed but an error may occur before any content is written. In this case, the CAR file will not be created, and the output stream will not be written to. In the case of an HTTP server, this means that the client will not receive a CAR header only, instead there will be an opportunity to return a proper HTTP error to the client.

The OnPut listener can be used to either track each Put() operation, or to just track the first Put() operation, which can be useful for setting HTTP headers in the assumption that the beginning of a valid CAR is about to be streamed.

func NewDeferredCarWriterForPath

func NewDeferredCarWriterForPath(outPath string, roots []cid.Cid, opts ...carv2.Option) *DeferredCarWriter

NewDeferredCarWriterForPath creates a DeferredCarWriter that will write to a file designated by the supplied path. The file will only be created on the first Put() operation.

No options are supplied to carstorage.NewWritable by default, add the car.WriteAsCarV1(true) option to write a CARv1 file.

func NewDeferredCarWriterForStream

func NewDeferredCarWriterForStream(outStream io.Writer, roots []cid.Cid, opts ...carv2.Option) *DeferredCarWriter

NewDeferredCarWriterForStream creates a DeferredCarWriter that will write to the supplied stream. The stream will only be written to on the first Put() operation.

The car.WriteAsCarV1(true) option will be supplied by default to carstorage.NewWritable as CARv2 is not a valid streaming format due to the header.

func (*DeferredCarWriter) BlockWriteOpener

func (dcw *DeferredCarWriter) BlockWriteOpener() linking.BlockWriteOpener

BlockWriteOpener returns a BlockWriteOpener that operates on this storage.

func (*DeferredCarWriter) Close

func (dcw *DeferredCarWriter) Close() (err error)

Close closes the underlying file, if one was created.

func (*DeferredCarWriter) Has

func (dcw *DeferredCarWriter) Has(ctx context.Context, key string) (bool, error)

Has returns false if the key was not already written to the CAR output.

func (*DeferredCarWriter) OnPut

func (dcw *DeferredCarWriter) OnPut(cb func(int), once bool)

OnPut will call a callback when each Put() operation is started. The argument to the callback is the number of bytes being written. If once is true, the callback will be removed after the first call.

func (*DeferredCarWriter) Put

func (dcw *DeferredCarWriter) Put(ctx context.Context, key string, content []byte) error

Put writes the given content to the CAR output stream, creating it if it doesn't exist yet.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL