[Pas2js] [feature request + ideas] Implementing TStream based classes (TBytesStream, TFileStream, TStringStream and so on)
silvioprog
silvioprog at gmail.com
Wed Nov 7 22:56:42 CET 2018
Hi.
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.
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.
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>
;
- classes which handles files (TFileStream, TBytesStream*) should be
implemented using the File API <https://www.w3.org/TR/FileAPI/>.
(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.
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.
Thank you!
--
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20181107/0943e21f/attachment.html>
More information about the Pas2js
mailing list