adonis-drive-r2
Version:
R2 driver for AdonisJS drive
111 lines (110 loc) • 3.72 kB
TypeScript
/// <reference types="@adonisjs/logger/build/adonis-typings/logger" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="@adonisjs/drive/build/adonis-typings" />
/// <reference types="node" />
import { Readable } from 'stream';
import { Upload } from '@aws-sdk/lib-storage';
import { LoggerContract } from '@ioc:Adonis/Core/Logger';
import { Visibility, WriteOptions, ContentHeaders, R2DriverConfig, R2DriverContract, DriveFileStats } from '@ioc:Adonis/Core/Drive';
import { Tag, S3Client } from '@aws-sdk/client-s3';
/**
* An implementation of the s3 driver for AdonisJS drive
*/
export declare class R2Driver implements R2DriverContract {
private config;
private logger;
/**
* Reference to the s3 client
*/
adapter: S3Client;
/**
* Name of the driver
*/
name: 'r2';
constructor(config: R2DriverConfig, logger: LoggerContract);
/**
* Transforms the write options to S3 properties
*/
private transformWriteOptions;
/**
* Transform content headers to S3 response content type
*/
private transformContentHeaders;
/**
* Set a new bucket at runtime and return a new driver instance
*/
bucket(bucket: string): R2Driver;
/**
* Set a new public url at runtime and return a new driver instance
*/
publicUrl(url: string): R2Driver;
/**
* Returns the file contents as a buffer. The buffer return
* value allows you to self choose the encoding when
* converting the buffer to a string.
*/
get(location: string): Promise<Buffer>;
/**
* Returns the file contents as a stream
*/
getStream(location: string): Promise<Readable>;
/**
* A boolean to find if the location path exists or not
*/
exists(location: string): Promise<boolean>;
/**
* Get the visibility for the bucket.
* For R2, visibility is set at the bucket level alone.
*/
getVisibility(): Promise<Visibility>;
/**
* Returns the file stats
*/
getStats(location: string): Promise<DriveFileStats>;
/**
* Returns the signed url for a given path
*/
getSignedUrl(location: string, options?: ContentHeaders & {
expiresIn?: string | number;
}): Promise<string>;
/**
* Returns URL to a given path
*/
getUrl(location: string): Promise<string>;
/**
* Write string|buffer contents to a destination. The missing
* intermediate directories will be created (if required).
*/
put(location: string, contents: Buffer | string, options?: WriteOptions): Promise<void>;
/**
* Write a stream to a destination. The missing intermediate
* directories will be created (if required).
*/
putStream(location: string, contents: NodeJS.ReadableStream, options?: WriteOptions & {
multipart?: boolean;
queueSize?: number;
partSize?: number;
leavePartsOnError?: boolean;
tags?: Tag[];
tap?: (stream: Upload) => void;
}): Promise<void>;
/**
* Not supported
*/
setVisibility(): Promise<void>;
/**
* Remove a given location path
*/
delete(location: string): Promise<void>;
/**
* Copy a given location path from the source to the destination.
* The missing intermediate directories will be created (if required)
*/
copy(source: string, destination: string, options?: WriteOptions): Promise<void>;
/**
* Move a given location path from the source to the destination.
* The missing intermediate directories will be created (if required)
*/
move(source: string, destination: string, options?: WriteOptions): Promise<void>;
}