[Pas2js] [feature request + ideas] Implementing TStream based classes (TBytesStream, TFileStream, TStringStream and so on)
Mattias Gaertner
nc-gaertnma at netcologne.de
Thu Nov 8 13:59:55 CET 2018
On Wed, 7 Nov 2018 18:56:42 -0300
silvioprog <silvioprog at gmail.com> wrote:
>[...]
> Firstly, thanks a lot Michael and Mattias for this incredible
> project! I'm using jQuery for years, but I'm surprised with the
> possibilities using this awesome transpiler to map my Pascal classes
> into JS/jQuery scripts.
You are welcome. :)
> So, I would appreciate to contribute by sending the classes for
> streaming (maybe starting from TByteStream), but I would like to
> understand if there is a reason for it is not implemented yet. I
> suspect it was for reasons like client side vs browsers security.
... and speed vs compatibility.
How do you propose to replace the methods ReadBuffer and WriteBuffer?
> I have some ideias to implement these classes, but it need to know if
> you agree with them:
>
> For browser based scripts:
>
> - classes which just handles buffers (TBytesStream, TStringStream)
> should be implemented using the ArrayBuffer object
> <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer>
Does that mean streams require at least ECMAScript6?
> - classes which handles files (TFileStream, TBytesStream*) should be
> implemented using the File API <https://www.w3.org/TR/FileAPI/>.
Makes sense for the browser platform.
What about the nodejs platform? As you stated below it provides an API,
that gives more complete and more direct access.
> (throwing an error if the browser doesn't support the ArrayBuffer
> object/File API)
>
> * It would use the TFileStream handle to save (into a file on the user
> drive) the buffer by the SaveToFile() method.
>
> For security reasons the browser doesn't allows to save files in the
> user drive via client-side, but overriding the File API you can do it
> via something like 'window.URL.createObjectURL' (nice for the
> SaveToFile() method), that is allowed in many browsers. Another
> option would be 'window.requestFileSystem ||
> window.webkitRequestFileSystem', enabled via some transpiler
> parameter.
What transpiler parameter?
> For NodeJS based scripts:
>
> - classes that just handle buffers should be implemented using the
> Buffer() <https://nodejs.org/api/buffer.html> (or something like
> this);
>
> - classes that handle files should be implemented using the File
> System <https://nodejs.org/api/fs.html>.
>
> What do you think?
>
> I have some drafts in pure JS, but I think it can be easily adapted to
> Pascal code via asm-blocks.
I bet you don't need asm-blocks.
A big challenge is the asynchronous file system access in the
browser. How do you want to handle this?
Mattias
More information about the Pas2js
mailing list