@@ -26,12 +26,12 @@ import { CarV1HeaderOrV2Pragma } from './header-validator.js'
2626 * @param {CarCodecOptions } [options]
2727 * @returns {Promise<CarHeader|CarV2Header> }
2828 */
29- export async function readHeader ( reader , strictVersion , options = { } ) {
29+ export async function readHeader ( reader , strictVersion , options ) {
3030 const length = decodeVarint ( await reader . upTo ( 8 ) , reader )
3131 if ( length === 0 ) {
3232 throw new Error ( 'Invalid CAR header (zero length)' )
3333 }
34- if ( options . maxHeaderLength != null && length > options . maxHeaderLength ) {
34+ if ( options ? .maxHeaderLength != null && length > options . maxHeaderLength ) {
3535 throw new RangeError ( `CAR header of length ${ length } exceeds maxHeaderLength of ${ options . maxHeaderLength } ` )
3636 }
3737 const header = await reader . exactly ( length , true )
@@ -64,7 +64,7 @@ export async function readHeader (reader, strictVersion, options = {}) {
6464 * @param {CarCodecOptions } [options]
6565 * @returns {Promise<CID> }
6666 */
67- async function readCid ( reader , options = { } ) {
67+ async function readCid ( reader , options ) {
6868 const cidStart = reader . pos
6969 const first = await reader . exactly ( 2 , false )
7070 if ( first [ 0 ] === CIDV0_BYTES . SHA2_256 && first [ 1 ] === CIDV0_BYTES . LENGTH ) {
@@ -82,7 +82,7 @@ async function readCid (reader, options = {}) {
8282 const mhLength = getMultihashLength ( await reader . upTo ( 8 ) )
8383 // full CID = version + codec varints (already consumed) + multihash
8484 const cidLength = Number ( reader . pos - cidStart ) + mhLength
85- if ( options . maxCidLength != null && cidLength > options . maxCidLength ) {
85+ if ( options ? .maxCidLength != null && cidLength > options . maxCidLength ) {
8686 throw new RangeError ( `CID of length ${ cidLength } exceeds maxCidLength of ${ options . maxCidLength } ` )
8787 }
8888 const bytes = await reader . exactly ( mhLength , true )
@@ -101,7 +101,7 @@ async function readCid (reader, options = {}) {
101101 * @param {CarCodecOptions } [options]
102102 * @returns {Promise<BlockHeader> }
103103 */
104- export async function readBlockHead ( reader , options = { } ) {
104+ export async function readBlockHead ( reader , options ) {
105105 // length includes a CID + Binary, where CID has a variable length
106106 // we have to deal with
107107 const start = reader . pos
@@ -112,7 +112,7 @@ export async function readBlockHead (reader, options = {}) {
112112 length += ( reader . pos - start )
113113 const cid = await readCid ( reader , options )
114114 const blockLength = length - Number ( reader . pos - start ) // subtract CID length
115- if ( options . maxBlockLength != null && blockLength > options . maxBlockLength ) {
115+ if ( options ? .maxBlockLength != null && blockLength > options . maxBlockLength ) {
116116 throw new RangeError ( `CAR block of length ${ blockLength } exceeds maxBlockLength of ${ options . maxBlockLength } ` )
117117 }
118118
@@ -124,7 +124,7 @@ export async function readBlockHead (reader, options = {}) {
124124 * @param {CarCodecOptions } [options]
125125 * @returns {Promise<Block> }
126126 */
127- async function readBlock ( reader , options = { } ) {
127+ async function readBlock ( reader , options ) {
128128 const { cid, blockLength } = await readBlockHead ( reader , options )
129129 const bytes = await reader . exactly ( blockLength , true )
130130 return { bytes, cid }
@@ -135,7 +135,7 @@ async function readBlock (reader, options = {}) {
135135 * @param {CarCodecOptions } [options]
136136 * @returns {Promise<BlockIndex> }
137137 */
138- async function readBlockIndex ( reader , options = { } ) {
138+ async function readBlockIndex ( reader , options ) {
139139 const offset = reader . pos
140140 const { cid, length, blockLength } = await readBlockHead ( reader , options )
141141 const index = { cid, length, blockLength, offset, blockOffset : reader . pos }
@@ -153,7 +153,7 @@ async function readBlockIndex (reader, options = {}) {
153153 * @param {CarCodecOptions } [options]
154154 * @returns {CarDecoder }
155155 */
156- export function createDecoder ( reader , options = { } ) {
156+ export function createDecoder ( reader , options ) {
157157 const headerPromise = ( async ( ) => {
158158 const header = await readHeader ( reader , undefined , options )
159159 if ( header . version === 2 ) {
0 commit comments