Compare commits

...

3 Commits

Author SHA1 Message Date
semantic-release-bot e6951fc9fe chore(release): 0.1.0-develop.6 [skip ci]
# [0.1.0-develop.6](https://git.lumeweb.com/LumeWeb/s5-js/compare/v0.1.0-develop.5...v0.1.0-develop.6) (2023-12-11)

### Features

* add downloadData method ([50ed08a](50ed08ac6a))
2023-12-11 04:34:48 +00:00
Derrick Hammer 31bf33c9a7
Merge remote-tracking branch 'origin/develop' into develop 2023-12-10 23:34:00 -05:00
Derrick Hammer 50ed08ac6a
feat: add downloadData method 2023-12-10 23:33:55 -05:00
5 changed files with 48 additions and 6 deletions

View File

@ -1,3 +1,10 @@
# [0.1.0-develop.6](https://git.lumeweb.com/LumeWeb/s5-js/compare/v0.1.0-develop.5...v0.1.0-develop.6) (2023-12-11)
### Features
* add downloadData method ([50ed08a](https://git.lumeweb.com/LumeWeb/s5-js/commit/50ed08ac6a23f9fa7e43450c0f8942124fa175cd))
# [0.1.0-develop.5](https://git.lumeweb.com/LumeWeb/s5-js/compare/v0.1.0-develop.4...v0.1.0-develop.5) (2023-12-11)

4
npm-shrinkwrap.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@lumeweb/s5-js",
"version": "0.1.0-develop.5",
"version": "0.1.0-develop.6",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@lumeweb/s5-js",
"version": "0.1.0-develop.5",
"version": "0.1.0-develop.6",
"dependencies": {
"@lumeweb/libs5": "^0.1.0-develop.79",
"@noble/hashes": "^1.3.2",

View File

@ -1,6 +1,6 @@
{
"name": "@lumeweb/s5-js",
"version": "0.1.0-develop.5",
"version": "0.1.0-develop.6",
"type": "module",
"module": "lib/index.js",
"main": "lib/index.js",

View File

@ -14,7 +14,12 @@ import {
uploadSmallFileRequest,
uploadLargeFileRequest,
} from "./methods/upload.js";
import { downloadFile, getCidUrl, getMetadata } from "./methods/download.js";
import {
downloadData,
downloadFile,
getCidUrl,
getMetadata,
} from "./methods/download.js";
import { defaultPortalUrl, ensureUrl } from "./utils/url.js";
@ -123,6 +128,7 @@ export class S5Client {
// Download
downloadFile = downloadFile;
downloadData = downloadData;
getCidUrl = getCidUrl;
getMetadata = getMetadata;

View File

@ -20,7 +20,7 @@ export type CustomDownloadOptions = BaseCustomOptions & {
path?: string;
range?: string;
responseType?: ResponseType;
subdomain?: boolean;
subdomain?: string;
};
export type CustomGetMetadataOptions = BaseCustomOptions & {
@ -45,7 +45,7 @@ export const DEFAULT_DOWNLOAD_OPTIONS = {
path: undefined,
range: undefined,
responseType: undefined,
subdomain: false,
subdomain: "",
};
const DEFAULT_GET_METADATA_OPTIONS = {
@ -139,3 +139,32 @@ export async function getMetadata(
return response.data;
}
/**
* Downloads in-memory data from a S5 cid.
* @param this - S5Client
* @param cid - 46-character cid, or a valid cid URL. Can be followed by a path. Note that the cid will not be encoded, so if your path might contain special characters, consider using `customOptions.path`.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - The data
*/
export async function downloadData(
this: S5Client,
cid: string,
customOptions?: CustomDownloadOptions,
): Promise<ArrayBuffer> {
const opts = {
...DEFAULT_DOWNLOAD_OPTIONS,
...this.customOptions,
...customOptions,
download: true,
};
const response = await this.executeRequest({
...opts,
method: "get",
extraPath: cid,
responseType: "arraybuffer",
});
return response.data;
}