I am trying to implement a stream module and apparently I have everything I
need but practically I'm unable to use streams.

If I instantiate a `new Gio.InputStream` I have the following error:
cannot create instance of abstract (non-instantiatable) type 'GInputStream'

I cannot even extend it ... so I've though "ok, maybe it's like an
interface, I implement it and that's it"

But then a JS class wouldn't work as base_stream for a
Gio.BufferedInputStream, and if I extend the JS class to be a
GObject.Object then:
Gjs-WARNING **: JS ERROR: TypeError: Object is of type GObject.Object -
cannot convert to GInputStream

where GInputStream is the one I cannot use in the first place.

I've reached full circle then so ... I wonder if anyone has any idea how to
use/create/extend streams in GJS (not talking about file streams but
streams in general) or if it's even possible.

In node, as example, I could do this and it will work:

```js

const { Readable } = require('stream');

class Counter extends Readable {
constructor(opt) {
super(opt);
this._max = 1000;
this._index = 1;
}

_read() {
const i = this._index++;
if (i > this._max)
this.push(null);
else {
const str = '' + i;
const buf = Buffer.from(str, 'ascii');
this.push(buf);
}
}
}

(new Counter).on('data', console.log);

```
_______________________________________________
javascript-list mailing list
javascript-list@gnome.org
https://mail.gnome.org/mailman/listinfo/javascript-list

Reply via email to