comparison xml/en/docs/njs/reference.xml @ 2585:7035221dbe37

Documented TextDecoder and TextEncoder in njs Reference.
author Yaroslav Zhuravlev <yar@nginx.com>
date Thu, 13 Aug 2020 21:42:01 +0100
parents cd97adddd757
children 5528961da54d
comparison
equal deleted inserted replaced
2584:88b4976778d2 2585:7035221dbe37
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> 7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">
8 8
9 <article name="Reference" 9 <article name="Reference"
10 link="/en/docs/njs/reference.html" 10 link="/en/docs/njs/reference.html"
11 lang="en" 11 lang="en"
12 rev="52"> 12 rev="53">
13 13
14 <section id="summary"> 14 <section id="summary">
15 15
16 <para> 16 <para>
17 <link doc="index.xml">njs</link> provides objects, methods and properties 17 <link doc="index.xml">njs</link> provides objects, methods and properties
672 </para> 672 </para>
673 673
674 </section> 674 </section>
675 675
676 676
677 <section id="textdecoder" name="Text Decoder">
678
679 <para>
680 The <literal>TextDecoder</literal>
681 produces a stream of code points
682 from a stream of bytes
683 (<link doc="changes.xml" id="njs0.4.3">0.4.3</link>).
684 </para>
685
686 <para>
687 <list type="tag">
688
689 <tag-name><literal>TextDecoder([[<value>encoding</value>],
690 <value>options</value>])</literal></tag-name>
691 <tag-desc>
692 Creates a new <literal>TextDecoder</literal> object
693 for specified <literal>encoding</literal>,
694 currently, only UTF-8 is supported.
695 The <literal>options</literal> is
696 <literal>TextDecoderOptions</literal> dictionary with the property:
697
698 <list type="tag">
699
700 <tag-name><literal>fatal</literal></tag-name>
701 <tag-desc>
702 boolean flag indicating if
703 <link id="textdecoder_decode"><literal>TextDecoder.decode()</literal></link>
704 must throw the <value>TypeError</value> exception when
705 a coding error is found, by default is <literal>false</literal>.
706 </tag-desc>
707
708 </list>
709 </tag-desc>
710
711 <tag-name id="textdecoder_encoding"><literal>TextDecoder.prototype.encoding</literal></tag-name>
712 <tag-desc>
713 Returns a string with the name of the encoding used by
714 <link id="textdecoder"><literal>TextDecoder()</literal></link>,
715 read-only.
716 </tag-desc>
717
718 <tag-name id="textdecoder_fatal"><literal>TextDecoder.prototype.fatal</literal></tag-name>
719 <tag-desc>
720 boolean flag, <literal>true</literal> if
721 the error mode is fatal,
722 read-only.
723 </tag-desc>
724
725 <tag-name id="textdecoder_ignorebom"><literal>TextDecoder.prototype.ignoreBOM</literal></tag-name>
726 <tag-desc>
727 boolean flag, <literal>true</literal> if
728 the byte order marker is ignored,
729 read-only.
730 </tag-desc>
731
732 <tag-name id="textdecoder_decode"><literal>TextDecoder.prototype.decode(<value>buffer</value>,
733 [<value>options</value>])</literal></tag-name>
734 <tag-desc>
735 Returns a string with the text
736 decoded from the <literal>buffer</literal> by
737 <link id="textdecoder"><literal>TextDecoder()</literal></link>.
738 The buffer can be <literal>ArrayBuffer</literal>.
739 The <literal>options</literal> is
740 <literal>TextDecodeOptions</literal> dictionary with the property:
741
742 <list type="tag">
743
744 <tag-name><literal>stream</literal></tag-name>
745 <tag-desc>
746 boolean flag indicating if
747 additional data will follow in subsequent calls to <literal>decode()</literal>:
748 <literal>true</literal> if processing the data in chunks, and
749 <literal>false</literal> for the final chunk
750 or if the data is not chunked.
751 By default is <literal>false</literal>.
752 </tag-desc>
753
754 </list>
755 <example>
756 >> (new TextDecoder()).decode(new Uint8Array([206,177,206,178]))
757 αβ
758 </example>
759 </tag-desc>
760
761 </list>
762 </para>
763
764 </section>
765
766
767 <section id="textencoder" name="Text Encoder">
768
769 <para>
770 The <literal>TextEncoder</literal> object
771 produces a byte stream with UTF-8 encoding
772 from a stream of code points
773 (<link doc="changes.xml" id="njs0.4.3">0.4.3</link>).
774 </para>
775
776 <para>
777 <list type="tag">
778
779 <tag-name><literal>TextEncoder()</literal></tag-name>
780 <tag-desc>
781 Returns a newly constructed <literal>TextEncoder</literal>
782 that will generate a byte stream with UTF-8 encoding.
783 </tag-desc>
784
785 <tag-name id="textencoder_encoding"><literal>TextEncoder.prototype.encoding</literal></tag-name>
786 <tag-desc>
787 Returns “<value>utf-8</value>”, read-only.
788 </tag-desc>
789
790 <tag-name id="textencoder_encode"><literal>TextEncoder.prototype.encode(<value>string</value>)</literal></tag-name>
791 <tag-desc>
792 Encodes <literal>string</literal> into a <literal>Uint8Array</literal>
793 with UTF-8 encoded text.
794 </tag-desc>
795
796 <tag-name id="textencoder_encodeinto"><literal>TextEncoder.prototype.encodeInto(<value>string</value>,
797 <value>uint8Array</value>)</literal></tag-name>
798 <tag-desc>
799 Encodes a <literal>string</literal> to UTF-8,
800 puts the result into destination <literal>Uint8Array</literal>, and
801 returns a dictionary object that shows the progress of the encoding.
802 The dictionary object contains two members:
803
804 <list type="tag">
805
806 <tag-name><literal>read</literal></tag-name>
807 <tag-desc>
808 the number of UTF-16 units of code from the source <literal>string</literal>
809 converted to UTF-8
810 </tag-desc>
811
812 <tag-name><literal>written</literal></tag-name>
813 <tag-desc>
814 the number of bytes modified in the destination <literal>Uint8Array</literal>
815 </tag-desc>
816
817 </list>
818 </tag-desc>
819
820 </list>
821 </para>
822
823 </section>
824
825
677 <section id="njs_api_timers" name="Timers"> 826 <section id="njs_api_timers" name="Timers">
678 827
679 <para> 828 <para>
680 <list type="tag"> 829 <list type="tag">
681 830