From 50472b77b93d0dd6d2135380bd2e982c82e00f0b Mon Sep 17 00:00:00 2001 From: Grigory Gorshkov Date: Tue, 13 Apr 2021 14:35:18 +0300 Subject: [PATCH] Fix prebuffer storage length (#252) * Fix prebuffer storage length #160 * up version Co-authored-by: Grigory Gorshkov --- package.json | 2 +- src/features/Prebuffer.ts | 2 +- src/features/__tests__/Prebuffer.test.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6f9e58e..f948bff 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@fridgefm/radio-core", "author": "Grigory Gorshkov", - "version": "3.0.1", + "version": "3.0.2", "description": "internet radio engine made on NodeJS platform", "license": "MIT", "main": "./lib/index.js", diff --git a/src/features/Prebuffer.ts b/src/features/Prebuffer.ts index c3030a7..3f088c8 100644 --- a/src/features/Prebuffer.ts +++ b/src/features/Prebuffer.ts @@ -17,7 +17,7 @@ export class Prebuffer { public modify(chunks: Buffer[]) { chunks.forEach((ch) => { - if (this._storage.length > this._prebufferLength) { + if (this._storage.length >= this._prebufferLength) { this._storage.shift(); } diff --git a/src/features/__tests__/Prebuffer.test.ts b/src/features/__tests__/Prebuffer.test.ts index 81b8378..b023ee9 100644 --- a/src/features/__tests__/Prebuffer.test.ts +++ b/src/features/__tests__/Prebuffer.test.ts @@ -23,10 +23,10 @@ describe('features/Prebuffer', () => { // overflow - the length stays the same instance.modify(createChunks('1234')); - expect(instance.getStorage().join('')).toEqual('4567890123'); + expect(instance.getStorage().join('')).toEqual('5678901234'); instance.modify(createChunks('1234')); - expect(instance.getStorage().join('')).toEqual('8901234123'); + expect(instance.getStorage().join('')).toEqual('9012341234'); }); it('uses default if length not set', () => {