Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fetcher): first step at optimization #30

Merged
merged 12 commits into from
Jan 9, 2025
Merged
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-storage/blob-fetcher",
"version": "2.4.3",
"version": "2.4.4-rc.0",
"description": "A blob fetcher that batches requests and reads multipart byterange responses.",
"main": "src/index.js",
"type": "module",
Expand Down Expand Up @@ -50,19 +50,24 @@
"./locator/indexing-service": {
"import": "./src/locator/indexing-service/index.js",
"types": "./dist/src/locator/indexing-service/index.d.ts"
},
"./tracing/tracing": {
"import": "./src/tracing/tracing.js",
"types": "./dist/src/tracing/tracing.d.ts"
}
},
"dependencies": {
"@cloudflare/workers-types": "^4.20241022.0",
"@ipld/dag-ucan": "^3.4.0",
"@opentelemetry/api": "^1.9.0",
"@storacha/indexing-service-client": "^2.0.0",
"@ucanto/interface": "^10.0.1",
"@web3-storage/blob-index": "^1.0.2",
"@web3-storage/content-claims": "^5.1.0",
"multiformats": "^13.1.0",
"multipart-byte-range": "^3.0.1",
"p-defer": "^4.0.1",
"p-queue": "^8.0.1",
"uint8arraylist": "^2.4.8",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
15 changes: 12 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 61 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,70 @@
import { ByteView, MultihashDigest } from 'multiformats'
import { Failure, Result, URI, DID } from '@ucanto/interface'
import { Range } from 'multipart-byte-range'
import { QueryError } from '@storacha/indexing-service-client/api'

export { ByteView, MultihashDigest } from 'multiformats'
export { Failure, Result, URI, DID, Principal } from '@ucanto/interface'
export { Range, SuffixRange, AbsoluteRange } from 'multipart-byte-range'

/**
* An absolute byte range to extract - always an array of two values
* corresponding to the first and last bytes (both inclusive). e.g.
*
* ```
* [100, 200]
* ```
*/
export type AbsoluteRange = [first: number, last: number]

/**
* A suffix byte range - always an array of one value corresponding to the
* first byte to start extraction from (inclusive). e.g.
*
* ```
* [900]
* ```
*
* If it is unknown how large a resource is, the last `n` bytes
* can be requested by specifying a negative value:
*
* ```
* [-100]
* ```
*/
export type SuffixRange = [first: number]

/**
* Byte range to extract - an array of one or two values corresponding to the
* first and last bytes (both inclusive). e.g.
*
* ```
* [100, 200]
* ```
*
* Omitting the second value requests all remaining bytes of the resource. e.g.
*
* ```
* [900]
* ```
*
* Alternatively, if it's unknown how large a resource is, the last `n` bytes
* can be requested by specifying a negative value:
*
* ```
* [-100]
* ```
*/
export type Range = AbsoluteRange | SuffixRange
Copy link
Member

Choose a reason for hiding this comment

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

Since we're not removing multipart-byte-range can we just re-use or re-export the types from there?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh right :)


export type ByteGetter = (range: AbsoluteRange) => Promise<ReadableStream<Uint8Array>>

export interface EncoderOptions {
/** Mime type of each part. */
contentType?: string
/** Total size of the object in bytes. */
totalSize?: number
/** Stream queuing strategy. */
strategy?: QueuingStrategy<Uint8Array>
}

export interface Abortable {
signal: AbortSignal
Expand Down
Loading
Loading