@ipld/car 4.1.2 → 4.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/car.js CHANGED
@@ -3,6 +3,7 @@ import { CarIndexer } from './lib/indexer.js'
3
3
  import { CarBlockIterator, CarCIDIterator } from './lib/iterator.js'
4
4
  import { CarWriter } from './lib/writer.js'
5
5
  import { CarIndexedReader } from './lib/indexed-reader.js'
6
+ import * as CarBufferWriter from './lib/buffer-writer.js'
6
7
 
7
8
  export {
8
9
  CarReader,
@@ -10,5 +11,6 @@ export {
10
11
  CarBlockIterator,
11
12
  CarCIDIterator,
12
13
  CarWriter,
13
- CarIndexedReader
14
+ CarIndexedReader,
15
+ CarBufferWriter
14
16
  }
package/cjs/car.js CHANGED
@@ -7,6 +7,7 @@ var indexer = require('./lib/indexer.js');
7
7
  var iterator = require('./lib/iterator.js');
8
8
  var writer = require('./lib/writer.js');
9
9
  var indexedReader = require('./lib/indexed-reader.js');
10
+ var bufferWriter = require('./lib/buffer-writer.js');
10
11
 
11
12
 
12
13
 
@@ -16,3 +17,4 @@ exports.CarBlockIterator = iterator.CarBlockIterator;
16
17
  exports.CarCIDIterator = iterator.CarCIDIterator;
17
18
  exports.CarWriter = writer.CarWriter;
18
19
  exports.CarIndexedReader = indexedReader.CarIndexedReader;
20
+ exports.CarBufferWriter = bufferWriter;
@@ -49,9 +49,10 @@ class CarBufferWriter {
49
49
  return close(this, options);
50
50
  }
51
51
  }
52
- const addRoot = (writer, root, {
53
- resize = false
54
- } = {}) => {
52
+ const addRoot = (writer, root, options = {}) => {
53
+ const {
54
+ resize = false
55
+ } = options;
55
56
  const {bytes, headerSize, byteOffset, roots} = writer;
56
57
  writer.roots.push(root);
57
58
  const size = headerLength(writer);
@@ -85,9 +86,10 @@ const addBlock = (writer, {cid, bytes}) => {
85
86
  writeBytes(writer, bytes);
86
87
  }
87
88
  };
88
- const close = (writer, {
89
- resize = false
90
- } = {}) => {
89
+ const close = (writer, options = {}) => {
90
+ const {
91
+ resize = false
92
+ } = options;
91
93
  const {roots, bytes, byteOffset, headerSize} = writer;
92
94
  const headerBytes = CBOR__namespace.encode({
93
95
  version: 1,
@@ -141,7 +143,8 @@ const calculateHeaderLength = rootLengths => {
141
143
  };
142
144
  const headerLength = ({roots}) => calculateHeaderLength(roots.map(cid => cid.bytes.byteLength));
143
145
  const estimateHeaderLength = (rootCount, rootByteLength = 36) => calculateHeaderLength(new Array(rootCount).fill(rootByteLength));
144
- const createWriter = (buffer, {roots = [], byteOffset = 0, byteLength = buffer.byteLength, headerSize = headerLength({ roots })} = {}) => {
146
+ const createWriter = (buffer, options = {}) => {
147
+ const {roots = [], byteOffset = 0, byteLength = buffer.byteLength, headerSize = headerLength({ roots })} = options;
145
148
  const bytes = new Uint8Array(buffer, byteOffset, byteLength);
146
149
  const writer = new CarBufferWriter(bytes, headerSize);
147
150
  for (const root of roots) {
package/esm/car.js CHANGED
@@ -6,11 +6,13 @@ import {
6
6
  } from './lib/iterator.js';
7
7
  import { CarWriter } from './lib/writer.js';
8
8
  import { CarIndexedReader } from './lib/indexed-reader.js';
9
+ import * as CarBufferWriter from './lib/buffer-writer.js';
9
10
  export {
10
11
  CarReader,
11
12
  CarIndexer,
12
13
  CarBlockIterator,
13
14
  CarCIDIterator,
14
15
  CarWriter,
15
- CarIndexedReader
16
+ CarIndexedReader,
17
+ CarBufferWriter
16
18
  };
@@ -24,9 +24,10 @@ class CarBufferWriter {
24
24
  return close(this, options);
25
25
  }
26
26
  }
27
- export const addRoot = (writer, root, {
28
- resize = false
29
- } = {}) => {
27
+ export const addRoot = (writer, root, options = {}) => {
28
+ const {
29
+ resize = false
30
+ } = options;
30
31
  const {bytes, headerSize, byteOffset, roots} = writer;
31
32
  writer.roots.push(root);
32
33
  const size = headerLength(writer);
@@ -60,9 +61,10 @@ export const addBlock = (writer, {cid, bytes}) => {
60
61
  writeBytes(writer, bytes);
61
62
  }
62
63
  };
63
- export const close = (writer, {
64
- resize = false
65
- } = {}) => {
64
+ export const close = (writer, options = {}) => {
65
+ const {
66
+ resize = false
67
+ } = options;
66
68
  const {roots, bytes, byteOffset, headerSize} = writer;
67
69
  const headerBytes = CBOR.encode({
68
70
  version: 1,
@@ -116,7 +118,8 @@ export const calculateHeaderLength = rootLengths => {
116
118
  };
117
119
  export const headerLength = ({roots}) => calculateHeaderLength(roots.map(cid => cid.bytes.byteLength));
118
120
  export const estimateHeaderLength = (rootCount, rootByteLength = 36) => calculateHeaderLength(new Array(rootCount).fill(rootByteLength));
119
- export const createWriter = (buffer, {roots = [], byteOffset = 0, byteLength = buffer.byteLength, headerSize = headerLength({ roots })} = {}) => {
121
+ export const createWriter = (buffer, options = {}) => {
122
+ const {roots = [], byteOffset = 0, byteLength = buffer.byteLength, headerSize = headerLength({ roots })} = options;
120
123
  const bytes = new Uint8Array(buffer, byteOffset, byteLength);
121
124
  const writer = new CarBufferWriter(bytes, headerSize);
122
125
  for (const root of roots) {
@@ -78,7 +78,8 @@ class CarBufferWriter {
78
78
  * @param {CID} root
79
79
  * @param {{resize?:boolean}} [options]
80
80
  */
81
- export const addRoot = (writer, root, { resize = false } = {}) => {
81
+ export const addRoot = (writer, root, options = {}) => {
82
+ const { resize = false } = options
82
83
  const { bytes, headerSize, byteOffset, roots } = writer
83
84
  writer.roots.push(root)
84
85
  const size = headerLength(writer)
@@ -137,7 +138,8 @@ export const addBlock = (writer, { cid, bytes }) => {
137
138
  * @param {object} [options]
138
139
  * @param {boolean} [options.resize]
139
140
  */
140
- export const close = (writer, { resize = false } = {}) => {
141
+ export const close = (writer, options = {}) => {
142
+ const { resize = false } = options
141
143
  const { roots, bytes, byteOffset, headerSize } = writer
142
144
 
143
145
  const headerBytes = CBOR.encode({ version: 1, roots })
@@ -266,15 +268,13 @@ export const estimateHeaderLength = (rootCount, rootByteLength = 36) =>
266
268
  * @param {number} [options.headerSize]
267
269
  * @returns {CarBufferWriter}
268
270
  */
269
- export const createWriter = (
270
- buffer,
271
- {
271
+ export const createWriter = (buffer, options = {}) => {
272
+ const {
272
273
  roots = [],
273
274
  byteOffset = 0,
274
275
  byteLength = buffer.byteLength,
275
276
  headerSize = headerLength({ roots })
276
- } = {}
277
- ) => {
277
+ } = options
278
278
  const bytes = new Uint8Array(buffer, byteOffset, byteLength)
279
279
 
280
280
  const writer = new CarBufferWriter(bytes, headerSize)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ipld/car",
3
- "version": "4.1.2",
3
+ "version": "4.1.5",
4
4
  "description": "Content Addressable aRchive format reader and writer",
5
5
  "main": "./cjs/car.js",
6
6
  "types": "./types/car.d.ts",
@@ -81,7 +81,7 @@
81
81
  "@types/chai": "^4.3.0",
82
82
  "@types/chai-as-promised": "^7.1.4",
83
83
  "@types/mocha": "^9.0.0",
84
- "@types/node": "^17.0.0",
84
+ "@types/node": "^18.0.0",
85
85
  "@types/varint": "^6.0.0",
86
86
  "@typescript-eslint/eslint-plugin": "^5.6.0",
87
87
  "@typescript-eslint/parser": "^5.6.0",
@@ -89,12 +89,12 @@
89
89
  "chai": "^4.3.4",
90
90
  "chai-as-promised": "^7.1.1",
91
91
  "ipjs": "^5.2.0",
92
- "ipld-garbage": "^4.0.10",
92
+ "ipld-garbage": "^5.0.0",
93
93
  "jsdoc4readme": "^1.4.0",
94
- "mocha": "^9.1.3",
95
- "polendina": "~2.0.1",
94
+ "mocha": "^10.0.0",
95
+ "polendina": "~3.1.0",
96
96
  "standard": "^17.0.0",
97
- "typescript": "~4.6.2"
97
+ "typescript": "~4.8.2"
98
98
  },
99
99
  "standard": {
100
100
  "ignore": [
package/types/car.d.ts CHANGED
@@ -4,5 +4,6 @@ import { CarBlockIterator } from "./lib/iterator.js";
4
4
  import { CarCIDIterator } from "./lib/iterator.js";
5
5
  import { CarWriter } from "./lib/writer.js";
6
6
  import { CarIndexedReader } from "./lib/indexed-reader.js";
7
- export { CarReader, CarIndexer, CarBlockIterator, CarCIDIterator, CarWriter, CarIndexedReader };
7
+ import * as CarBufferWriter from "./lib/buffer-writer.js";
8
+ export { CarReader, CarIndexer, CarBlockIterator, CarCIDIterator, CarWriter, CarIndexedReader, CarBufferWriter };
8
9
  //# sourceMappingURL=car.d.ts.map
@@ -1,9 +1,9 @@
1
- export function addRoot(writer: CarBufferWriter, root: CID, { resize }?: {
1
+ export function addRoot(writer: CarBufferWriter, root: CID, options?: {
2
2
  resize?: boolean | undefined;
3
3
  } | undefined): void;
4
4
  export function blockLength({ cid, bytes }: Block): number;
5
5
  export function addBlock(writer: CarBufferWriter, { cid, bytes }: Block): void;
6
- export function close(writer: CarBufferWriter, { resize }?: {
6
+ export function close(writer: CarBufferWriter, options?: {
7
7
  resize?: boolean | undefined;
8
8
  } | undefined): Uint8Array;
9
9
  export function resizeHeader(writer: CarBufferWriter, byteLength: number): void;
@@ -12,7 +12,7 @@ export function headerLength({ roots }: {
12
12
  roots: CID[];
13
13
  }): number;
14
14
  export function estimateHeaderLength(rootCount: number, rootByteLength?: number | undefined): number;
15
- export function createWriter(buffer: ArrayBuffer, { roots, byteOffset, byteLength, headerSize }?: {
15
+ export function createWriter(buffer: ArrayBuffer, options?: {
16
16
  roots?: import("multiformats/cid").CID[] | undefined;
17
17
  byteOffset?: number | undefined;
18
18
  byteLength?: number | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"buffer-writer.d.ts","sourceRoot":"","sources":["../../lib/buffer-writer.js"],"names":[],"mappings":"AAgFO,gCAJI,eAAe,QACf,GAAG;;qBA0Bb;AAUM,4CAHI,KAAK,GACH,MAAM,CAKlB;AAMM,iCAHI,eAAe,kBACf,KAAK,QAYf;AAOM,8BAJI,eAAe;;2BA2BzB;AAMM,qCAHI,eAAe,cACf,MAAM,QAShB;AAqCM,mDAHI,MAAM,EAAE,GACN,MAAM,CAWlB;AAUM;IAHmB,KAAK,EAApB,GAAG,EAAE;IACH,MAAM,CAG4C;AAYxD,gDAJI,MAAM,wCAEJ,MAAM,CAG+C;AAuB3D,qCARI,W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