admin管理员组

文章数量:1401673

I have hdf5 file created using c++ application.i want to read the same hdf5 file inside browser using javascript.

Hdf5 file will be download from server using xhr or web socket request and the content of the file will be stored in javascript variable then i want to read the content of the variable.

Please tell me any javascript library available to read the hdf5 inside browser.

i tried ".node" but it supports only for nodejs.

Is it possible to convert the above library to support reading inside browser.

I have hdf5 file created using c++ application.i want to read the same hdf5 file inside browser using javascript.

Hdf5 file will be download from server using xhr or web socket request and the content of the file will be stored in javascript variable then i want to read the content of the variable.

Please tell me any javascript library available to read the hdf5 inside browser.

i tried "https://github./HDF-NI/hdf5.node" but it supports only for nodejs.

Is it possible to convert the above library to support reading inside browser.

Share Improve this question edited Sep 9, 2017 at 4:32 hpaulj 232k14 gold badges255 silver badges381 bronze badges asked Jul 21, 2016 at 12:09 SrinivasSrinivas 3915 silver badges14 bronze badges 5
  • Can you please disclose what C++ application you used to generate hdf5 file? It will help us to understand what similar technology might be ok for your case? – Hafizur Rahman Commented May 24, 2018 at 23:10
  • C++ application will write 3D geometry data like vertices,normals in to HDF5 file and same file will be used in javascript to render it inside the webbrowser using webgl.I used [link] (support.hdfgroup/HDF5/doc/cpplus_RM/index.html) – Srinivas Commented May 28, 2018 at 5:48
  • C++ application will create 3D geometry data link vertices,normal into hdf5 file and same file will be used in JavaScript to render in web browser using Webgl. I used hdf5 1.10 and this link link – Srinivas Commented May 28, 2018 at 5:52
  • @Srinivas did you ever find a solution for this? – Brian Bienvenu Commented Dec 7, 2018 at 11:29
  • @Brian Bienvenu No i didnt find a solution.Instead of using hdf5 i used custom binary file. – Srinivas Commented Dec 28, 2018 at 11:25
Add a ment  | 

2 Answers 2

Reset to default 2

It is only able to read a subset of HDF5 files, but this is something that works: https://github./usnistgov/jsfive

It basically covers all the files that can be read by the pyfive library (https://github./jjhelmus/pyfive), as it is a direct port of that library.

The best two libraries that I found are jsfive and h5wasm:

Sample code jsfive:

$(document).ready(function() {
    $("#datafile").change(async function loadData() {
        var file_input = $("#datafile")[0];
        var file = file_input.files[0]; // only one file allowed
        let datafilename = file.name;
        let reader = new FileReader();
        reader.onloadend = function(evt) { 
          let barr = evt.target.result;
          var f = new hdf5.File(barr, datafilename);
          let value = f.get('main').value
          let attrs = f.get('main').attrs
          // do somthing with f
        }
    })
})
<!DOCTYPE html>
<html lang="eng">

<head>
</head>

<body>

  <input type="file" id="datafile" name="file">
  
  <!-- Import JQuery -->
  <script src="https://ajax.googleapis./ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <!-- Import JSFive -->
  <script src="https://cdn.jsdelivr/npm/[email protected]/dist/hdf5.js">
    <!-- Import main JS -->
    <
    script src = "app.js" >
  </script>
</body>

</html>

Sample code h5wasm:

import * as hdf5 from "https://cdn.jsdelivr/npm/h5wasm@latest/dist/esm/hdf5_hl.js";

await hdf5.ready;

$(document).ready(function() {
    $("#datafile").change(async function loadData() {
        let file = $("#datafile")[0].files[0];
        let data_filename = file.name;
        let ab = await file.arrayBuffer();
        hdf5.FS.writeFile(data_filename, new Uint8Array(ab));
        let f = new hdf5.File(data_filename, "r");
        // do somthing with f
        f.close()
    })
})
<!DOCTYPE html>
<html lang="eng">

<head>
</head>

<body>
    <input type="file" id="datafile" name="file">

    <!-- Import JQuery -->
    <script src="https://ajax.googleapis./ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <!-- Import main JS -->
    <script type="module" src="app.js" ></script>
</body>

</html>

Also interesting jsfive with callback:

function storeTarget(result, file_name) {
  f = new hdf5.File(result, file_name);
}

$("#datafile").change(async function loadSource() {
    var file_input = $("#datafile")[0];
    var file = file_input.files[0];
    let datafilename = file.name;
    const reader = new FileReader();
    reader.readAsArrayBuffer(file);
    reader.onload = () => storeTarget(reader.result, datafilename);
})

本文标签: nodejsHow to read hdf5 file in javascript inside browserStack Overflow