Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Amended FITSBlock.header type to FITSHeader[] in @observerly/fits. #22

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { describe, expect, it, suite } from 'vitest'

import { parseFITSHeaderBlock } from '../'
import { parseFITSHeaderBlock } from '..'

/*****************************************************************************************************************/

Expand Down
19 changes: 14 additions & 5 deletions src/header/readFITSHeaderFromBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

/*****************************************************************************************************************/

import { FITSBlock } from '../types'
import { FITSBlock, FITSHeader } from '../types'

import { parseFITSHeaderBlock } from '../header'
import { parseFITSHeaderRow, parseFITSHeaderBlock } from '../header'

import { readBlockAsArrayBuffer } from '../utilities'

Expand All @@ -25,7 +25,10 @@ import { readBlockAsArrayBuffer } from '../utilities'
export const readFITSHeaderFromBlocks = async (
file: File,
blocks: FITSBlock[]
): Promise<FITSBlock[]> => {
): Promise<{
headers: FITSHeader[]
blocks: FITSBlock[]
}> => {
for (const block of blocks) {
// obtain the individual slices of the file:
const blob = file.slice(block.offsetStart, block.offsetEnd)
Expand All @@ -34,7 +37,10 @@ export const readFITSHeaderFromBlocks = async (
const { headers, end, parsed } = await readBlockAsArrayBuffer(blob, parseFITSHeaderBlock)

// the raw parsed string from the array buffer:
block.headers = headers
for (const header of headers) {
block.headers.push(parseFITSHeaderRow(header))
}

// make a note of the block that has been parsed:
block.parsed = parsed

Expand All @@ -43,5 +49,8 @@ export const readFITSHeaderFromBlocks = async (
}

// return the original blocks:
return blocks
return {
blocks,
headers: blocks.flatMap(block => block.headers)
}
}
6 changes: 5 additions & 1 deletion src/types/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

/*****************************************************************************************************************/

import { type FITSHeader } from '../types'

/*****************************************************************************************************************/

export interface FITSBlock {
/**
*
Expand All @@ -24,7 +28,7 @@ export interface FITSBlock {
* The ArrayBuffer as a raw parsed array of strings
*
*/
headers: string[]
headers: FITSHeader[]
/**
*
*
Expand Down
Loading