{"modulePath":"github.com/data-preservation-programs/singularity","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package file\n\n## Variables\n\n```go\nvar (\n\tErrNoFileRangeRecord    = errors.New(\"missing file range record\")\n\tErrNoJobRecord          = errors.New(\"missing job record\")\n\tErrNoFilecoinDeals      = errors.New(\"no filecoin deals available\")\n\tErrByteOffsetBeyondFile = errors.New(\"byte offset would exceed file size\")\n)\n```\n\n## Types\n\n```go\ntype DealsForFileRange struct {\n\tFileRange model.FileRange\n\tDeals     []model.Deal\n}\n```\n\n```go\ntype DefaultHandler struct{}\n```\n\n```go\nfunc (DefaultHandler) GetFileDealsHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tid uint64,\n) ([]DealsForFileRange, error)\n```\nGetFileDealsHandler retrieves the deals associated with a given file ID.\n\nThe method operates by querying the database using the provided file ID. It starts by selecting the relevant file range, joining it with the cars table on the job\\_id field, and then joining with the deals table using the piece\\_cid field.\n\nParameters:\n\n  - ctx: The context for managing timeouts and cancellation.\n  - db: The gorm.DB instance for database operations.\n  - id: The ID of the file for which deals need to be retrieved.\n\nReturns:\n\n  - A slice of DealsForFileRange containing the deals associated with the provided file ID for each FileRange.\n  - An error if any issues occur during the database operation.\n\n```go\nfunc (DefaultHandler) GetFileHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tid uint64,\n) (*model.File, error)\n```\nGetFileHandler retrieves a file with its associated file ranges from the database using a given file ID.\n\nThis function preloads the associated FileRanges for the queried file. If no record is found matching the provided ID, it returns an ErrNotFound error.\n\nParameters:\n\n  - ctx: The context for managing timeouts and cancellation.\n  - db: The gorm.DB instance for database operations.\n  - id: The ID of the file to be retrieved.\n\nReturns:\n\n  - A pointer to the retrieved model.File, if found.\n  - An error if any issues occur during the database operation, including when the file is not found.\n\n```go\nfunc (DefaultHandler) PrepareToPackFileHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tfileID uint64,\n) (int64, error)\n```\n\n```go\nfunc (DefaultHandler) PushFileHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tpreparation string,\n\tsource string,\n\tfileInfo Info,\n) (*model.File, error)\n```\nPushFileHandler pushes a file to the database using specified preparation and source details.\n\nThis function retrieves the source attachment by its preparation and source. If the source isn't attached to the given preparation, an ErrNotFound error is returned. The function then validates the file's existence in the storage system using the RClone handler. If the file is validated successfully, it is then pushed to the database.\n\nParameters:\n\n  - ctx: The context for managing timeouts and cancellation.\n  - db: The gorm.DB instance for database operations.\n  - preparation: The preparation ID or name.\n  - source: The source ID or name.\n  - fileInfo: Information regarding the file to be pushed.\n\nReturns:\n\n  - A pointer to the pushed model.File, if successful.\n  - An error if any issues occur during the operation, including when the source isn't attached to the preparation, if the file doesn't exist in the storage system, or if the file already exists\n\n```go\nfunc (DefaultHandler) RetrieveFileHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tfilecoinRetriever FilecoinRetriever,\n\tid uint64,\n) (data io.ReadSeekCloser, name string, modTime time.Time, err error)\n```\nRetrieveFileHandler retrieves the actual bytes for a file on disk using a given file ID.\n\n### For now, this function only works if the file remains available in its original source storage {#hdr-For_now__this_function_only_works_if_the_file_remains_available_in_its_original_source_storage}\n\nParameters: - ctx: The context for managing timeouts and cancellation. - db: The gorm.DB instance for database operations. - id: The ID of the file to be retrieved.\n\nReturns: - A ReadSeekCloser for the given file - the name of the file - An error if any issues occur during the database operation, including when the file is not found.\n\n```go\ntype FilecoinRetriever interface {\n\tRetrieve(ctx context.Context, c cid.Cid, rangeStart int64, rangeEnd int64, sps []string, out io.Writer) error\n\tRetrieveReader(ctx context.Context, c cid.Cid, rangeStart int64, rangeEnd int64, sps []string) (io.ReadCloser, error)\n}\n```\n\n```go\ntype Handler interface {\n\tPrepareToPackFileHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tfileID uint64) (int64, error)\n\n\tGetFileDealsHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tid uint64,\n\t) ([]DealsForFileRange, error)\n\n\tGetFileHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tid uint64,\n\t) (*model.File, error)\n\n\tPushFileHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tpreparation string,\n\t\tsource string,\n\t\tfileInfo Info,\n\t) (*model.File, error)\n\n\tRetrieveFileHandler(\n\t\tctx context.Context,\n\t\tdb *gorm.DB,\n\t\tretriever FilecoinRetriever,\n\t\tid uint64,\n\t) (data io.ReadSeekCloser, name string, modTime time.Time, err error)\n}\n```\n\n```go\nvar Default Handler = \u0026DefaultHandler{}\n```\n\n```go\ntype Info struct {\n\tPath string `json:\"path\"` // Path to the new file, relative to the source\n}\n```\n\n```go\ntype MockFile struct {\n\tmock.Mock\n}\n```\n\n```go\nfunc (m *MockFile) GetFileDealsHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tid uint64,\n) ([]DealsForFileRange, error)\n```\n\n```go\nfunc (m *MockFile) GetFileHandler(ctx context.Context, db *gorm.DB, id uint64) (*model.File, error)\n```\n\n```go\nfunc (m *MockFile) PrepareToPackFileHandler(ctx context.Context, db *gorm.DB, fileID uint64) (int64, error)\n```\n\n```go\nfunc (m *MockFile) PushFileHandler(ctx context.Context, db *gorm.DB, preparation string, source string, fileInfo Info) (*model.File, error)\n```\n\n```go\nfunc (m *MockFile) RetrieveFileHandler(\n\tctx context.Context,\n\tdb *gorm.DB,\n\tretriever FilecoinRetriever,\n\tid uint64,\n) (data io.ReadSeekCloser, name string, modTime time.Time, err error)\n```\n\n```go\ntype UnableToServeRangeError struct {\n\tStart int64\n\tEnd   int64\n\tErr   error\n}\n```\n\n```go\nfunc (e UnableToServeRangeError) Error() string\n```\n\n```go\nfunc (e UnableToServeRangeError) Unwrap() error\n```\n\n","path":"github.com/data-preservation-programs/singularity/handler/file","name":"file","synopsis":"","isRedistributable":true}
