Skip to content

Commit

Permalink
fix: update file format usage (#39)
Browse files Browse the repository at this point in the history
* feat: update file format usage

* Update src/client.js

Co-authored-by: Eric Guan <[email protected]>

---------

Co-authored-by: Eric Guan <[email protected]>
  • Loading branch information
AmeanAsad and guanzo authored Nov 3, 2023
1 parent 362c97e commit d8b1266
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class Saturn {
* @param {string} [config.customerFallbackURL]
* @param {number} [config.fallbackLimit]
* @param {boolean} [config.experimental]
* @param {string} [config.format]
* @param {import('./storage/index.js').Storage} [config.storage]
*/
constructor (config = {}) {
Expand All @@ -41,6 +42,7 @@ export class Saturn {
logURL: 'https://twb3qukm2i654i3tnvx36char40aymqq.lambda-url.us-west-2.on.aws/',
orchURL: 'https://orchestrator.strn.pl/nodes?maxNodes=100',
authURL: 'https://su4hesnyinnwvtk3h2rkauh5ja0qrisq.lambda-url.us-west-2.on.aws/',
format: 'car',
fallbackLimit: 5,
connectTimeout: 5_000,
downloadTimeout: 0
Expand Down Expand Up @@ -68,7 +70,7 @@ export class Saturn {
* @returns {Promise<object>}
*/
async fetchCIDWithRace (cidPath, opts = {}) {
const options = Object.assign({}, this.config, { format: 'car' }, opts)
const options = Object.assign({}, this.config, opts)
if (!opts.originFallback) {
const [cid] = (cidPath ?? '').split('/')
CID.parse(cid)
Expand Down Expand Up @@ -159,7 +161,7 @@ export class Saturn {
* @returns {Promise<object>}
*/
async fetchCID (cidPath, opts = {}) {
const options = Object.assign({}, this.config, { format: 'car' }, opts)
const options = Object.assign({}, this.config, opts)
if (!opts.originFallback) {
const [cid] = (cidPath ?? '').split('/')
CID.parse(cid)
Expand Down Expand Up @@ -264,7 +266,7 @@ export class Saturn {
})
}
let byteCount = 0
const fetchOptions = Object.assign(opts, { format: 'car' }, options)
const fetchOptions = Object.assign(opts, options)
const byteChunks = await this.fetchContent(cidPath, fetchOptions)
for await (const chunk of byteChunks) {
// avoid sending duplicate chunks
Expand Down Expand Up @@ -347,6 +349,7 @@ export class Saturn {
*/
async * fetchContent (cidPath, opts = {}) {
let res, controller, log
opts = Object.assign({}, this.config, opts)

if (opts.raceNodes) {
({ res, controller, log } = await this.fetchCIDWithRace(cidPath, opts))
Expand All @@ -365,10 +368,10 @@ export class Saturn {

try {
const itr = metricsIterable(asAsyncIterable(res.body))
if (opts.format === 'car') {
yield * extractVerifiedContent(cidPath, itr)
} else {
if (!opts.format) {
yield * itr
} else {
yield * extractVerifiedContent(cidPath, itr)
}
} catch (err) {
log.error = err.message
Expand Down

0 comments on commit d8b1266

Please sign in to comment.