From 6a913ee2677dc8a6cdc6d9c8b39ce5dc528b9eeb Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 14 Dec 2024 22:55:20 -0500 Subject: [PATCH] Couple more --- src/cramFile/codecs/external.ts | 2 +- src/cramFile/file.ts | 24 +----------------------- src/cramFile/slice/index.ts | 3 --- 3 files changed, 2 insertions(+), 27 deletions(-) diff --git a/src/cramFile/codecs/external.ts b/src/cramFile/codecs/external.ts index 0e44a55a..c6b8b224 100644 --- a/src/cramFile/codecs/external.ts +++ b/src/cramFile/codecs/external.ts @@ -1,5 +1,5 @@ import CramCodec, { Cursor, Cursors } from './_base' -import { CramMalformedError, CramUnimplementedError } from '../../errors' +import { CramUnimplementedError } from '../../errors' import { CramFileBlock } from '../file' import CramSlice from '../slice' import { parseItf8 } from '../util' diff --git a/src/cramFile/file.ts b/src/cramFile/file.ts index 73077269..d745c269 100644 --- a/src/cramFile/file.ts +++ b/src/cramFile/file.ts @@ -102,7 +102,6 @@ export default class CramFile { } } - // can just stat this object like a filehandle read(length: number, position: number) { return this.file.read(length, position) } @@ -153,7 +152,6 @@ export default class CramFile { const { majorVersion } = await this.getDefinition() const sectionParsers = getSectionParsers(majorVersion) let position = sectionParsers.cramFileDefinition.maxLength - const { cramContainerHeader1 } = sectionParsers // skip with a series of reads to the proper container let currentContainer: CramContainer | undefined @@ -260,11 +258,6 @@ export default class CramFile { const { majorVersion } = await this.getDefinition() const sectionParsers = getSectionParsers(majorVersion) const { cramBlockHeader } = sectionParsers - const { size: fileSize } = await this.file.stat() - - if (position + cramBlockHeader.maxLength >= fileSize) { - return undefined - } const buffer = await this.file.read(cramBlockHeader.maxLength, position) return parseItem(buffer, cramBlockHeader.parser, 0, position) @@ -282,16 +275,7 @@ export default class CramFile { size = section.maxLength, preReadBuffer?: Uint8Array, ) { - let buffer: Uint8Array - if (preReadBuffer) { - buffer = preReadBuffer - } else { - const { size: fileSize } = await this.file.stat() - if (position + size >= fileSize) { - return undefined - } - buffer = await this.file.read(size, position) - } + const buffer = preReadBuffer ?? (await this.file.read(size, position)) const data = parseItem(buffer, section.parser, 0, position) if (data._size !== size) { throw new CramMalformedError( @@ -351,9 +335,6 @@ export default class CramFile { const { majorVersion } = await this.getDefinition() const sectionParsers = getSectionParsers(majorVersion) const blockHeader = await this.readBlockHeader(position) - if (blockHeader === undefined) { - return undefined - } const blockContentPosition = blockHeader._endPosition const d = await this.file.read( @@ -381,9 +362,6 @@ export default class CramFile { sectionParsers.cramBlockCrc32, blockContentPosition + blockHeader.compressedSize, ) - if (crc === undefined) { - return undefined - } block.crc32 = crc.crc32 // check the block data crc32 diff --git a/src/cramFile/slice/index.ts b/src/cramFile/slice/index.ts index 4c01cfb2..fc44947f 100644 --- a/src/cramFile/slice/index.ts +++ b/src/cramFile/slice/index.ts @@ -198,9 +198,6 @@ export default class CramSlice { const { majorVersion } = await this.file.getDefinition() const sectionParsers = getSectionParsers(majorVersion) const containerHeader = await this.container.getHeader() - if (!containerHeader) { - throw new Error('no container header detected') - } const header = await this.file.readBlock( containerHeader._endPosition + this.containerPosition,