Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ipld/car

Package Overview
Dependencies
Maintainers
3
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ipld/car - npm Package Compare versions

Comparing version 3.1.13 to 3.1.14

76

cjs/browser-test/test-reader.js
'use strict';
var readerBrowser = require('../lib/reader-browser.js');
var writerBrowser = require('../lib/writer-browser.js');
var Block = require('multiformats/block');
var sha2 = require('multiformats/hashes/sha2');
var raw = require('multiformats/codecs/raw');
var common = require('./common.js');
var verifyStoreReader = require('./verify-store-reader.js');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var Block__namespace = /*#__PURE__*/_interopNamespace(Block);
var raw__namespace = /*#__PURE__*/_interopNamespace(raw);
describe('CarReader fromBytes()', () => {

@@ -78,2 +105,51 @@ it('complete', async () => {

});
it('handle zero-byte chunks', async () => {
const {writer, out} = await writerBrowser.CarWriter.create([]);
const b1 = await Block__namespace.encode({
value: Uint8Array.from([
0,
1,
2
]),
hasher: sha2.sha256,
codec: raw__namespace
});
writer.put(b1);
const b2 = await Block__namespace.encode({
value: Uint8Array.from([]),
hasher: sha2.sha256,
codec: raw__namespace
});
writer.put(b2);
const b3 = await Block__namespace.encode({
value: Uint8Array.from([
3,
4,
5
]),
hasher: sha2.sha256,
codec: raw__namespace
});
writer.put(b3);
const closePromise = writer.close();
const reader = await readerBrowser.CarReader.fromIterable(out);
const b1a = await reader.get(b1.cid);
common.assert.isDefined(b1a);
common.assert.deepStrictEqual(b1a && Array.from(b1a.bytes), [
0,
1,
2
]);
const b2a = await reader.get(b2.cid);
common.assert.isDefined(b2a);
common.assert.deepStrictEqual(b2a && Array.from(b2a.bytes), []);
const b3a = await reader.get(b3.cid);
common.assert.isDefined(b3a);
common.assert.deepStrictEqual(b3a && Array.from(b3a.bytes), [
3,
4,
5
]);
await closePromise;
});
it('bad argument', async () => {

@@ -80,0 +156,0 @@ for (const arg of [

4

cjs/lib/decoder.js

@@ -177,3 +177,3 @@ 'use strict';

const chunk = await readChunk();
if (chunk.length === 0) {
if (chunk == null) {
break;

@@ -228,3 +228,3 @@ }

if (next.done) {
return new Uint8Array(0);
return null;
}

@@ -231,0 +231,0 @@ return next.value;

@@ -33,3 +33,5 @@ 'use strict';

await writer.write(cid.bytes);
await writer.write(bytes);
if (bytes.length) {
await writer.write(bytes);
}
},

@@ -36,0 +38,0 @@ async close() {

'use strict';
var reader = require('../lib/reader.js');
var writer = require('../lib/writer.js');
var Block = require('multiformats/block');
var sha2 = require('multiformats/hashes/sha2');
var raw = require('multiformats/codecs/raw');
var common = require('./common.js');
var verifyStoreReader = require('./verify-store-reader.js');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var Block__namespace = /*#__PURE__*/_interopNamespace(Block);
var raw__namespace = /*#__PURE__*/_interopNamespace(raw);
describe('CarReader fromBytes()', () => {

@@ -78,2 +105,51 @@ it('complete', async () => {

});
it('handle zero-byte chunks', async () => {
const {writer: writer$1, out} = await writer.CarWriter.create([]);
const b1 = await Block__namespace.encode({
value: Uint8Array.from([
0,
1,
2
]),
hasher: sha2.sha256,
codec: raw__namespace
});
writer$1.put(b1);
const b2 = await Block__namespace.encode({
value: Uint8Array.from([]),
hasher: sha2.sha256,
codec: raw__namespace
});
writer$1.put(b2);
const b3 = await Block__namespace.encode({
value: Uint8Array.from([
3,
4,
5
]),
hasher: sha2.sha256,
codec: raw__namespace
});
writer$1.put(b3);
const closePromise = writer$1.close();
const reader$1 = await reader.CarReader.fromIterable(out);
const b1a = await reader$1.get(b1.cid);
common.assert.isDefined(b1a);
common.assert.deepStrictEqual(b1a && Array.from(b1a.bytes), [
0,
1,
2
]);
const b2a = await reader$1.get(b2.cid);
common.assert.isDefined(b2a);
common.assert.deepStrictEqual(b2a && Array.from(b2a.bytes), []);
const b3a = await reader$1.get(b3.cid);
common.assert.isDefined(b3a);
common.assert.deepStrictEqual(b3a && Array.from(b3a.bytes), [
3,
4,
5
]);
await closePromise;
});
it('bad argument', async () => {

@@ -80,0 +156,0 @@ for (const arg of [

import { CarReader } from '../lib/reader-browser.js';
import { CarWriter } from '../lib/writer-browser.js';
import * as Block from 'multiformats/block';
import { sha256 } from 'multiformats/hashes/sha2';
import * as raw from 'multiformats/codecs/raw';
import {

@@ -85,2 +89,51 @@ carBytes,

});
it('handle zero-byte chunks', async () => {
const {writer, out} = await CarWriter.create([]);
const b1 = await Block.encode({
value: Uint8Array.from([
0,
1,
2
]),
hasher: sha256,
codec: raw
});
writer.put(b1);
const b2 = await Block.encode({
value: Uint8Array.from([]),
hasher: sha256,
codec: raw
});
writer.put(b2);
const b3 = await Block.encode({
value: Uint8Array.from([
3,
4,
5
]),
hasher: sha256,
codec: raw
});
writer.put(b3);
const closePromise = writer.close();
const reader = await CarReader.fromIterable(out);
const b1a = await reader.get(b1.cid);
assert.isDefined(b1a);
assert.deepStrictEqual(b1a && Array.from(b1a.bytes), [
0,
1,
2
]);
const b2a = await reader.get(b2.cid);
assert.isDefined(b2a);
assert.deepStrictEqual(b2a && Array.from(b2a.bytes), []);
const b3a = await reader.get(b3.cid);
assert.isDefined(b3a);
assert.deepStrictEqual(b3a && Array.from(b3a.bytes), [
3,
4,
5
]);
await closePromise;
});
it('bad argument', async () => {

@@ -87,0 +140,0 @@ for (const arg of [

@@ -147,3 +147,3 @@ import varint from 'varint';

const chunk = await readChunk();
if (chunk.length === 0) {
if (chunk == null) {
break;

@@ -198,3 +198,3 @@ }

if (next.done) {
return new Uint8Array(0);
return null;
}

@@ -201,0 +201,0 @@ return next.value;

@@ -24,3 +24,5 @@ import varint from 'varint';

await writer.write(cid.bytes);
await writer.write(bytes);
if (bytes.length) {
await writer.write(bytes);
}
},

@@ -27,0 +29,0 @@ async close() {

import { CarReader } from '../lib/reader.js';
import { CarWriter } from '../lib/writer.js';
import * as Block from 'multiformats/block';
import { sha256 } from 'multiformats/hashes/sha2';
import * as raw from 'multiformats/codecs/raw';
import {

@@ -85,2 +89,51 @@ carBytes,

});
it('handle zero-byte chunks', async () => {
const {writer, out} = await CarWriter.create([]);
const b1 = await Block.encode({
value: Uint8Array.from([
0,
1,
2
]),
hasher: sha256,
codec: raw
});
writer.put(b1);
const b2 = await Block.encode({
value: Uint8Array.from([]),
hasher: sha256,
codec: raw
});
writer.put(b2);
const b3 = await Block.encode({
value: Uint8Array.from([
3,
4,
5
]),
hasher: sha256,
codec: raw
});
writer.put(b3);
const closePromise = writer.close();
const reader = await CarReader.fromIterable(out);
const b1a = await reader.get(b1.cid);
assert.isDefined(b1a);
assert.deepStrictEqual(b1a && Array.from(b1a.bytes), [
0,
1,
2
]);
const b2a = await reader.get(b2.cid);
assert.isDefined(b2a);
assert.deepStrictEqual(b2a && Array.from(b2a.bytes), []);
const b3a = await reader.get(b3.cid);
assert.isDefined(b3a);
assert.deepStrictEqual(b3a && Array.from(b3a.bytes), [
3,
4,
5
]);
await closePromise;
});
it('bad argument', async () => {

@@ -87,0 +140,0 @@ for (const arg of [

@@ -220,3 +220,3 @@ import varint from 'varint'

* reader when finished
* @param {() => Promise<Uint8Array>} readChunk
* @param {() => Promise<Uint8Array|null>} readChunk
* @returns {BytesReader}

@@ -235,3 +235,3 @@ */

const chunk = await readChunk()
if (chunk.length === 0) {
if (chunk == null) {
break

@@ -305,3 +305,3 @@ }

if (next.done) {
return new Uint8Array(0)
return null
}

@@ -308,0 +308,0 @@ return next.value

@@ -52,3 +52,6 @@ import varint from 'varint'

await writer.write(cid.bytes)
await writer.write(bytes)
if (bytes.length) {
// zero-length blocks are valid, but it'd be safer if we didn't write them
await writer.write(bytes)
}
},

@@ -55,0 +58,0 @@

{
"name": "@ipld/car",
"version": "3.1.13",
"version": "3.1.14",
"description": "Content Addressable aRchive format reader and writer",

@@ -5,0 +5,0 @@ "main": "./cjs/car.js",

/* eslint-env mocha */
import { CarReader } from '@ipld/car/reader'
import { CarWriter } from '@ipld/car/writer'
import * as Block from 'multiformats/block'
import { sha256 } from 'multiformats/hashes/sha2'
import * as raw from 'multiformats/codecs/raw'
import { carBytes, makeIterable, assert } from './common.js'

@@ -85,2 +89,27 @@ import {

it('handle zero-byte chunks', async () => {
// write 3 blocks, the middle one has zero bytes - this is a valid dag-pb form
// so it's important that we can handle it .. also we may just be dealing with
// an asynciterator that provides zero-length chunks
const { writer, out } = await CarWriter.create([])
const b1 = await Block.encode({ value: Uint8Array.from([0, 1, 2]), hasher: sha256, codec: raw })
writer.put(b1)
const b2 = await Block.encode({ value: Uint8Array.from([]), hasher: sha256, codec: raw })
writer.put(b2)
const b3 = await Block.encode({ value: Uint8Array.from([3, 4, 5]), hasher: sha256, codec: raw })
writer.put(b3)
const closePromise = writer.close()
const reader = await CarReader.fromIterable(out) // read from the writer
const b1a = await reader.get(b1.cid)
assert.isDefined(b1a)
assert.deepStrictEqual(b1a && Array.from(b1a.bytes), [0, 1, 2])
const b2a = await reader.get(b2.cid)
assert.isDefined(b2a)
assert.deepStrictEqual(b2a && Array.from(b2a.bytes), [])
const b3a = await reader.get(b3.cid)
assert.isDefined(b3a)
assert.deepStrictEqual(b3a && Array.from(b3a.bytes), [3, 4, 5])
await closePromise
})
it('bad argument', async () => {

@@ -87,0 +116,0 @@ for (const arg of [new Uint8Array(0), true, false, null, undefined, 'string', 100, { obj: 'nope' }]) {

@@ -21,6 +21,6 @@ /**

* reader when finished
* @param {() => Promise<Uint8Array>} readChunk
* @param {() => Promise<Uint8Array|null>} readChunk
* @returns {BytesReader}
*/
export function chunkReader(readChunk: () => Promise<Uint8Array>): BytesReader;
export function chunkReader(readChunk: () => Promise<Uint8Array | null>): BytesReader;
/**

@@ -27,0 +27,0 @@ * @param {AsyncIterable<Uint8Array>} asyncIterable

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc