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

Fetch opaque datasets with h5grove as binary #1587

Merged
merged 3 commits into from
Mar 13, 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
1 change: 1 addition & 0 deletions packages/app/src/App.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@

.error {
composes: error from global;
grid-area: vis;
}

.error > span {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,11 @@ exports[`test file matches snapshot 1`] = `
"class": "Opaque",
"tag": "",
},
"value": """,
"value": Uint8Array [
0,
17,
34,
],
},
{
"name": "byte_string_1D",
Expand All @@ -813,10 +817,10 @@ exports[`test file matches snapshot 1`] = `
"class": "Opaque",
"tag": "",
},
"value": [
"
"",
""",
"value": Uint8Array [
0,
17,
34,
],
},
{
Expand All @@ -832,7 +836,16 @@ exports[`test file matches snapshot 1`] = `
"class": "Opaque",
"tag": "",
},
"value": [AxiosError: Request failed with status code 500],
"value": Uint8Array [
150,
177,
135,
93,
0,
0,
0,
0,
],
},
{
"name": "datetime64_not-a-time_scalar",
Expand All @@ -847,7 +860,16 @@ exports[`test file matches snapshot 1`] = `
"class": "Opaque",
"tag": "",
},
"value": [AxiosError: Request failed with status code 500],
"value": Uint8Array [
0,
0,
0,
0,
0,
0,
0,
128,
],
},
{
"name": "complex64_scalar",
Expand Down
10 changes: 8 additions & 2 deletions packages/app/src/providers/h5grove/h5grove-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ProvidedEntity,
Value,
} from '@h5web/shared/hdf5-models';
import { DTypeClass } from '@h5web/shared/hdf5-models';
import type { AxiosRequestConfig } from 'axios';

import { DataProviderApi } from '../api';
Expand Down Expand Up @@ -45,9 +46,13 @@ export class H5GroveApi extends DataProviderApi {
): Promise<H5GroveDataResponse> {
const { dataset } = params;

if (dataset.type.class === DTypeClass.Opaque) {
return new Uint8Array(await this.fetchBinaryData(params));
}

const DTypedArray = h5groveTypedArrayFromDType(dataset.type);
if (DTypedArray) {
const buffer = await this.fetchBinaryData(params);
const buffer = await this.fetchBinaryData(params, true);
const array = new DTypedArray(buffer);
return hasScalarShape(dataset) ? array[0] : array;
}
Expand Down Expand Up @@ -149,6 +154,7 @@ export class H5GroveApi extends DataProviderApi {

private async fetchBinaryData(
params: ValuesStoreParams,
safe = false,
): Promise<ArrayBuffer> {
const { data } = await this.cancellableFetchValue(
'/data/',
Expand All @@ -157,7 +163,7 @@ export class H5GroveApi extends DataProviderApi {
path: params.dataset.path,
selection: params.selection,
format: 'bin',
dtype: 'safe',
dtype: safe ? 'safe' : undefined,
},
'arraybuffer',
);
Expand Down
6 changes: 5 additions & 1 deletion packages/lib/src/vis/raw/RawVis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ interface Props {

function RawVis(props: Props) {
const { value } = props;
const valueAsStr = JSON.stringify(value, null, 2);

const valueAsStr =
value instanceof Uint8Array
axelboc marked this conversation as resolved.
Show resolved Hide resolved
? `Uint8Array [ ${value.toString()} ]`
: JSON.stringify(value, null, 2);

return (
<div className={styles.root}>
Expand Down