Skip to content

Commit

Permalink
Couple more
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 15, 2024
1 parent 57971d6 commit 6a913ee
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/cramFile/codecs/external.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
24 changes: 1 addition & 23 deletions src/cramFile/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/cramFile/slice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6a913ee

Please sign in to comment.