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

@travetto/model

Package Overview
Dependencies
Maintainers
1
Versions
371
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/model - npm Package Compare versions

Comparing version 3.1.7 to 3.1.8

2

package.json
{
"name": "@travetto/model",
"version": "3.1.7",
"version": "3.1.8",
"description": "Datastore abstraction for core operations.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -320,3 +320,3 @@ <!-- This file was generated by @travetto/doc and should not be modified directly -->

async deleteStream(location: string): Promise<void>;
// Expiry Support
// Expiry
async deleteExpired<T extends ModelType>(cls: Class<T>): Promise<number>;

@@ -323,0 +323,0 @@ // Storage Support

@@ -9,7 +9,14 @@ import { AppError, Class } from '@travetto/base';

export class ModelStreamUtil {
static checkRange(start: number, end: number, size: number): void {
if (Number.isNaN(start) || Number.isNaN(end) || !Number.isFinite(start) || start < 0 || end >= size) {
static enforceRange(start: number, end: number | undefined, size: number): [start: number, end: number] {
end ??= size - 1;
if (Number.isNaN(start) || Number.isNaN(end) || !Number.isFinite(start) || start >= size || start < 0) {
throw new AppError('Invalid position, out of range', 'data');
}
if (end >= size) {
end = size - 1;
}
return [start, end];
}
}

@@ -196,5 +196,4 @@ import fs from 'fs/promises';

const meta = await this.describeStream(location);
end ??= meta.size - 1;
ModelStreamUtil.checkRange(start, end, meta.size);
[start, end] = ModelStreamUtil.enforceRange(start, end, meta.size);

@@ -201,0 +200,0 @@ const stream = createReadStream(file, { start, end });

@@ -255,4 +255,5 @@ import { Readable } from 'stream';

const buffer = streams.get(location)!;
end ??= (buffer.length - 1);
ModelStreamUtil.checkRange(start, end, buffer.length);
[start, end] = ModelStreamUtil.enforceRange(start, end, buffer.length);
const stream = await StreamUtil.bufferToStream(buffer.subarray(start, end + 1));

@@ -259,0 +260,0 @@ return { stream, range: [start, end] };

@@ -101,5 +101,10 @@ import assert from 'assert';

const partialOverbounded = await service.getStreamPartial(meta.hash, 20, 40);
const subContent4 = (await StreamUtil.toBuffer(partialOverbounded.stream)).toString('utf8');
assert(subContent4.length === 6);
assert(subContent4.endsWith('xyz'));
await assert.rejects(() => service.getStreamPartial(meta.hash, -10, 10));
await assert.rejects(() => service.getStreamPartial(meta.hash, 0, 27));
await assert.rejects(() => service.getStreamPartial(meta.hash, 30, 37));
}
}
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