Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class Bee {
*/
async uploadData(
postageBatchId: BatchId | Uint8Array | string,
data: string | Uint8Array,
data: string | Uint8Array | Blob | Readable,
options?: RedundantUploadOptions,
requestOptions?: BeeRequestOptions,
): Promise<UploadResult> {
Expand Down
3 changes: 2 additions & 1 deletion src/modules/bytes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Optional } from 'cafe-utility'
import { Readable } from 'stream'
import type { BeeRequestOptions, DownloadOptions, RedundantUploadOptions, ReferenceInformation } from '../types'
import { UploadResult } from '../types'
import { UploadResultBody } from '../types/schema/upload'
Expand All @@ -22,7 +23,7 @@ const endpoint = 'bytes'
*/
export async function upload(
requestOptions: BeeRequestOptions,
data: string | Uint8Array,
data: string | Uint8Array | Blob | Readable,
postageBatchId: BatchId,
options?: RedundantUploadOptions,
): Promise<UploadResult> {
Expand Down
8 changes: 7 additions & 1 deletion src/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ export interface BeeRequestConfig extends RequestInit {
* @param config Internal settings and/or Bee settings
*/
export async function http<T>(options: BeeRequestOptions, config: BeeRequestConfig): Promise<BeeResponse<T>> {
const requestConfig: BeeRequestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, config, options)
const rawData = config.data
const requestConfig: BeeRequestConfig = Objects.deepMerge3(
DEFAULT_HTTP_CONFIG,
{ ...config, data: undefined },
options,
)
requestConfig.data = rawData

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just data: rawData instead of data: undefined? This part is not fully clear why we explicitly assign undefined first

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that also works. deepmerge3 sets data to undefined so it doesn't really matter. the point is to reassign requestConfig.data so that it persists.


if (options.signal) {
requestConfig.signal = options.signal
Expand Down
6 changes: 3 additions & 3 deletions src/utils/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export function isTag(value: unknown): value is Tag {
* @param value
* @throws TypeError if not valid
*/
export function assertData(value: unknown): asserts value is string | Uint8Array {
if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
throw new TypeError('Data must be either string or Uint8Array!')
export function assertData(value: unknown): asserts value is string | Uint8Array | Blob | stream.Readable {
if (typeof value !== 'string' && !(value instanceof Uint8Array) && !(value instanceof Blob) && !isReadable(value)) {
throw new TypeError('Data must be either string, Uint8Array, Blob or Readable!')
}
}

Expand Down
Loading