kelp_fake: Create a kelp fake object.

Description Details Public fields Methods

Description

Create a kelp fake object.

Create a kelp fake object.

Details

Exposes same interface as kelp() but stores files to a local temp directory. Can be used for testing when a SeaweedFS instance might not be available. All operations will create file ids will return simulated data which matches structure of SeaweedFS. Uploading or downloading files will copy to/from the temp directory.

Public fields

seaweed_url

Base URL for seaweed master. Can be a dummy value.

Methods

Public methods


Method new()

Create a mock kelp client object for testing which doesn't require a Seaweed instance to be running.

Usage
kelp_fake$new(seaweed_url)
Arguments
seaweed_url

Root URL of Seaweed (can be anything for testing)

Returns

A new kelp_fake object


Method upload_file()

Upload file

Usage
kelp_fake$upload_file(path, collection = NULL)
Arguments
path

Path to file to be uploaded

collection

Collection name, acts as a namespace for files.

Returns

The uploaded file ID.


Method download_file()

Download file

If called with an id matching an R object uploaded via kelp$upload_object() then this will download raw bytes which can be converted back to R object at later point using unserialize or readRDS.

Usage
kelp_fake$download_file(id, path = tempfile(), collection = NULL)
Arguments
id

File ID to read

path

Path to download file to

collection

Optional collection name this file belongs to.

Returns

The file contents


Method upload_object()

Upload arbitrary R object

This serializes R object to raw vector of bytes and then saves bytes.

Usage
kelp_fake$upload_object(object, collection = NULL)
Arguments
object

Object to be uploaded

collection

Collection name, acts as a namespace.

Returns

The uploaded file ID.


Method download_object()

Download arbitrary R object

If data downloaded is not unserializable (i.e. it was written using kelp$upload_file()) then this will throw an error. See kelp$download_file() to download as a file.

Usage
kelp_fake$download_object(id, collection = NULL)
Arguments
id

File ID to download

collection

Optional collection name this file belongs to.

Returns

The R object.


Method upload_raw()

Upload vector of raw bytes.

Usage
kelp_fake$upload_raw(raw, collection = NULL)
Arguments
raw

Object to be uploaded

collection

Collection name, acts as a namespace.

Returns

The uploaded file ID.


Method download_raw()

Download vector of raw bytes.

Usage
kelp_fake$download_raw(id, collection = NULL)
Arguments
id

File ID to download

collection

Optional collection name this file belongs to.

Returns

Vector of raw bytes.


Method delete()

Delete file

Usage
kelp_fake$delete(id, collection = NULL)
Arguments
id

File ID to delete

collection

Optional collection name this file belongs to. This helps speedup lookup - only the single id will be deleted. See kelp$delete_collection() to remove an entire collection.

Returns

Nothing, called for side effects


Method delete_collection()

Delete a collection of files

Usage
kelp_fake$delete_collection(collection)
Arguments
collection

Collection name.

Returns

Nothing, called for side effects


mrc-ide/kelp documentation built on Dec. 21, 2021, 10:04 p.m.