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

using vsicurl in node / browser ? #67

Open
vsharma-next opened this issue Jan 29, 2024 · 3 comments
Open

using vsicurl in node / browser ? #67

vsharma-next opened this issue Jan 29, 2024 · 3 comments

Comments

@vsharma-next
Copy link

Hello. Love this work. I think this might be one of those watershed experiments that will have a big impact.

Q: Is vsicurl supported ? I would love to replace geotiff.js dependency and just use gdal's vsicurl. This is what I have tried.

code :

//vsicurl.js

const initGdalJs = require('gdal3.js/node');

async function main() {
  try {
    const Gdal = await initGdalJs();

    const result = await Gdal.open(
      'http://127.0.0.1:8080/data/simple-polygon-line-point.tif',
      [],
      ['vsicurl']
    );
    console.log(result);
  } catch (error) {
    console.error(error);
  }
}

main();

result:

node vsicurl.js

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "ErrnoError: FS error".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Node.js v18.16.0

Since @rouault seems to also be following this effort, perhaps he can comment as well ?

I have tried it in the browser and it does not work there either - perhaps not too much of a surprise will all the sandbox/security stuff.

Any suggestions ?

Thanks !

@vsharma-next vsharma-next changed the title using vsicurl in node / brower ? using vsicurl in node / browser ? Jan 29, 2024
@bugra9
Copy link
Owner

bugra9 commented Feb 3, 2024

Hi @vsharma-next,

I am glad you love this work, thank you.

/vsicurl/ is not currently supported. I compiled Gdal with Curl to support it but couldn't get it to work. The issue is that Curl is not fully compatible with emscripten. I'll try again when I have more time.

Alternatively, I can release a new version by making the Emscripten Filesystem API public so you can use the following code:

const data = await fetch('http://127.0.0.1:8080/data/simple-polygon-line-point.tif').then(response => response.arrayBuffer());
Gdal.FS.writeFile('/input/simple-polygon-line-point.tif', new Int8Array(data));
const result = await Gdal.open('/input/simple-polygon-line-point.tif');

Would that work for you?

@vsharma-next
Copy link
Author

This is a great idea. I think given that OPFS will become more and more prevalent, this API will come in handy.
I googled a bit and it seems that Emscripten Filesystem API will be overhauld by WasmFS API which will most likely include support for OPFS (https://github.com/emscripten-core/emscripten/blob/main/test/wasmfs/wasmfs_opfs.c).

bugra9 added a commit that referenced this issue Feb 7, 2024
@bugra9
Copy link
Owner

bugra9 commented Feb 7, 2024

@vsharma-next, I exported the Module from Emscripten to version 2.8.0. Can you try the code below with this version?

const Gdal = await initGdalJs();

const data = await fetch('https://gdal3.js.org/test/data/simple-polygon-line-point.tif').then(response => response.arrayBuffer());
Gdal.Module.FS.writeFile('/input/simple-polygon-line-point.tif', new Int8Array(data));
const result = await Gdal.open('/input/simple-polygon-line-point.tif');
console.log(result);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants