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

Make H5Wasm demo more permissive #1131

Merged
merged 2 commits into from
Jun 13, 2022
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
14 changes: 6 additions & 8 deletions apps/demo/src/h5wasm/DropZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function DropZone(props: Props) {

const { getRootProps, getInputProps, open, isDragActive, fileRejections } =
useDropzone({
accept: { 'application/x-hdf5': EXT },
multiple: false,
noClick: true,
noKeyboard: true,
Expand All @@ -46,7 +45,7 @@ function DropZone(props: Props) {
'data-disabled': isReadingFile || undefined,
})}
>
<input {...getInputProps()} />
<input {...getInputProps()} accept={EXT.join(',')} />
<div className={styles.inner}>
{isDragActive ? (
<p className={styles.dropIt}>Drop it!</p>
Expand All @@ -58,12 +57,11 @@ function DropZone(props: Props) {
or use a file picker instead
</button>
</p>
<p
className={styles.hint}
role={fileRejections.length > 0 ? 'alert' : undefined}
>
Extensions allowed: <strong>{EXT.join(' ')}</strong>
</p>
{fileRejections.length > 1 && (
<p className={styles.hint} role="alert">
Please drop a single file
axelboc marked this conversation as resolved.
Show resolved Hide resolved
</p>
)}
</>
)}
</div>
Expand Down
16 changes: 5 additions & 11 deletions packages/h5wasm/src/h5wasm-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,13 @@ import {
isH5WasmSoftLink,
} from './guards';
import type { H5WasmAttributes, H5WasmEntity } from './models';
import {
convertMetadataToDType,
convertSelectionToRanges,
isHDF5,
} from './utils';
import { convertMetadataToDType, convertSelectionToRanges } from './utils';

export class H5WasmApi extends ProviderApi {
private readonly file: Promise<H5WasmFile>;

public constructor(filename: string, buffer: ArrayBuffer) {
super(filename);

if (!isHDF5(buffer)) {
throw new Error('Expected valid HDF5 file');
}

this.file = this.initFile(buffer);
}

Expand Down Expand Up @@ -118,7 +109,10 @@ export class H5WasmApi extends ProviderApi {
const file = await this.file;

const h5wEntity = file.get(path);
assertNonNull(h5wEntity, `No entity found at ${path}`);
assertNonNull(
h5wEntity,
path === '/' ? `Expected valid HDF5 file` : `No entity found at ${path}`
axelboc marked this conversation as resolved.
Show resolved Hide resolved
);

return h5wEntity;
}
Expand Down
9 changes: 0 additions & 9 deletions packages/h5wasm/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ import {
} from './guards';
import type { NumericMetadata } from './models';

// https://www.loc.gov/preservation/digital/formats/fdd/fdd000229.shtml
const HDF5_MAGIC_NUMBER = [0x89, 0x48, 0x44, 0x46, 0x0d, 0x0a, 0x1a, 0x0a]; // ASCII: \211 HDF \r \n \032 \n

export function isHDF5(buffer: ArrayBuffer): boolean {
return new Uint8Array(buffer.slice(0, HDF5_MAGIC_NUMBER.length)).every(
(num, i) => num === HDF5_MAGIC_NUMBER[i]
);
}

export function convertNumericMetadataToDType(
metadata: NumericMetadata
): NumericType {
Expand Down