Convert CP437 using JavaScript Encoding API in Browser










0















Is there a way to convert CP437 to UTF8 in browser using new Encoding API?



I've tried this:



decoder = new TextDecoder('CP437');
decoder = new TextDecoder('IBM437');


but got error:




Uncaught RangeError: Failed to construct 'TextDecoder': The encoding
label provided ('IBM437') is invalid.
at :1:11




I've also tried with dashes CP-437 and IBM-437.



On GNU/Linux I can use iconv, I've found project iconv-js, but it seems it only convert one encoding.



Is compiling iconv to JavaScript using Emscripten the only option?










share|improve this question

















  • 1





    It seems that there is node-iconv package on npm.

    – jcubic
    Nov 15 '18 at 8:25






  • 1





    it seems this encoding label is NOT supported, use either an iso-xxx and/or windows-xxx encoding (eg look here the polyfill github.com/inexorabletash/text-encoding)

    – Nikos M.
    Nov 15 '18 at 9:18












  • It seems that node-iconv is only for node because it have C code.

    – jcubic
    Nov 15 '18 at 18:23















0















Is there a way to convert CP437 to UTF8 in browser using new Encoding API?



I've tried this:



decoder = new TextDecoder('CP437');
decoder = new TextDecoder('IBM437');


but got error:




Uncaught RangeError: Failed to construct 'TextDecoder': The encoding
label provided ('IBM437') is invalid.
at :1:11




I've also tried with dashes CP-437 and IBM-437.



On GNU/Linux I can use iconv, I've found project iconv-js, but it seems it only convert one encoding.



Is compiling iconv to JavaScript using Emscripten the only option?










share|improve this question

















  • 1





    It seems that there is node-iconv package on npm.

    – jcubic
    Nov 15 '18 at 8:25






  • 1





    it seems this encoding label is NOT supported, use either an iso-xxx and/or windows-xxx encoding (eg look here the polyfill github.com/inexorabletash/text-encoding)

    – Nikos M.
    Nov 15 '18 at 9:18












  • It seems that node-iconv is only for node because it have C code.

    – jcubic
    Nov 15 '18 at 18:23













0












0








0








Is there a way to convert CP437 to UTF8 in browser using new Encoding API?



I've tried this:



decoder = new TextDecoder('CP437');
decoder = new TextDecoder('IBM437');


but got error:




Uncaught RangeError: Failed to construct 'TextDecoder': The encoding
label provided ('IBM437') is invalid.
at :1:11




I've also tried with dashes CP-437 and IBM-437.



On GNU/Linux I can use iconv, I've found project iconv-js, but it seems it only convert one encoding.



Is compiling iconv to JavaScript using Emscripten the only option?










share|improve this question














Is there a way to convert CP437 to UTF8 in browser using new Encoding API?



I've tried this:



decoder = new TextDecoder('CP437');
decoder = new TextDecoder('IBM437');


but got error:




Uncaught RangeError: Failed to construct 'TextDecoder': The encoding
label provided ('IBM437') is invalid.
at :1:11




I've also tried with dashes CP-437 and IBM-437.



On GNU/Linux I can use iconv, I've found project iconv-js, but it seems it only convert one encoding.



Is compiling iconv to JavaScript using Emscripten the only option?







javascript utf-8 character-encoding






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 8:24









jcubicjcubic

34.3k30124227




34.3k30124227







  • 1





    It seems that there is node-iconv package on npm.

    – jcubic
    Nov 15 '18 at 8:25






  • 1





    it seems this encoding label is NOT supported, use either an iso-xxx and/or windows-xxx encoding (eg look here the polyfill github.com/inexorabletash/text-encoding)

    – Nikos M.
    Nov 15 '18 at 9:18












  • It seems that node-iconv is only for node because it have C code.

    – jcubic
    Nov 15 '18 at 18:23












  • 1





    It seems that there is node-iconv package on npm.

    – jcubic
    Nov 15 '18 at 8:25






  • 1





    it seems this encoding label is NOT supported, use either an iso-xxx and/or windows-xxx encoding (eg look here the polyfill github.com/inexorabletash/text-encoding)

    – Nikos M.
    Nov 15 '18 at 9:18












  • It seems that node-iconv is only for node because it have C code.

    – jcubic
    Nov 15 '18 at 18:23







1




1





It seems that there is node-iconv package on npm.

– jcubic
Nov 15 '18 at 8:25





It seems that there is node-iconv package on npm.

– jcubic
Nov 15 '18 at 8:25




1




1





it seems this encoding label is NOT supported, use either an iso-xxx and/or windows-xxx encoding (eg look here the polyfill github.com/inexorabletash/text-encoding)

– Nikos M.
Nov 15 '18 at 9:18






it seems this encoding label is NOT supported, use either an iso-xxx and/or windows-xxx encoding (eg look here the polyfill github.com/inexorabletash/text-encoding)

– Nikos M.
Nov 15 '18 at 9:18














It seems that node-iconv is only for node because it have C code.

– jcubic
Nov 15 '18 at 18:23





It seems that node-iconv is only for node because it have C code.

– jcubic
Nov 15 '18 at 18:23












1 Answer
1






active

oldest

votes


















0














Encoding API is limited and don't support CP437. So the process of conversion look like this:



create empty npm project using



npm init


then install



npm install -g browserify
npm install iconv-lite buffer-shims


create index.js file with:



window.iconv = require('iconv-lite');
window.Buffer = require('buffer-shims');


run



browserify -o iconv.js index.js


and now you have browser version of iconv lite library (in iconv.js file) that will work from browser.



With it you can run:



 document.getElementById('file').addEventListener('change', function(event) 
var reader = new FileReader();
reader.onload = function(event)
var utf8_str = iconv.decode(Buffer.from(event.target.result), 'CP437');
;
reader.readAsArrayBuffer(event.target.files[0]);
);


you will need to have:



<input id="file" type="file" />


and



<meta charset="utf-8"/>


so iconv-lite can convert string to utf-8, which is the only valid charset.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315114%2fconvert-cp437-using-javascript-encoding-api-in-browser%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Encoding API is limited and don't support CP437. So the process of conversion look like this:



    create empty npm project using



    npm init


    then install



    npm install -g browserify
    npm install iconv-lite buffer-shims


    create index.js file with:



    window.iconv = require('iconv-lite');
    window.Buffer = require('buffer-shims');


    run



    browserify -o iconv.js index.js


    and now you have browser version of iconv lite library (in iconv.js file) that will work from browser.



    With it you can run:



     document.getElementById('file').addEventListener('change', function(event) 
    var reader = new FileReader();
    reader.onload = function(event)
    var utf8_str = iconv.decode(Buffer.from(event.target.result), 'CP437');
    ;
    reader.readAsArrayBuffer(event.target.files[0]);
    );


    you will need to have:



    <input id="file" type="file" />


    and



    <meta charset="utf-8"/>


    so iconv-lite can convert string to utf-8, which is the only valid charset.






    share|improve this answer



























      0














      Encoding API is limited and don't support CP437. So the process of conversion look like this:



      create empty npm project using



      npm init


      then install



      npm install -g browserify
      npm install iconv-lite buffer-shims


      create index.js file with:



      window.iconv = require('iconv-lite');
      window.Buffer = require('buffer-shims');


      run



      browserify -o iconv.js index.js


      and now you have browser version of iconv lite library (in iconv.js file) that will work from browser.



      With it you can run:



       document.getElementById('file').addEventListener('change', function(event) 
      var reader = new FileReader();
      reader.onload = function(event)
      var utf8_str = iconv.decode(Buffer.from(event.target.result), 'CP437');
      ;
      reader.readAsArrayBuffer(event.target.files[0]);
      );


      you will need to have:



      <input id="file" type="file" />


      and



      <meta charset="utf-8"/>


      so iconv-lite can convert string to utf-8, which is the only valid charset.






      share|improve this answer

























        0












        0








        0







        Encoding API is limited and don't support CP437. So the process of conversion look like this:



        create empty npm project using



        npm init


        then install



        npm install -g browserify
        npm install iconv-lite buffer-shims


        create index.js file with:



        window.iconv = require('iconv-lite');
        window.Buffer = require('buffer-shims');


        run



        browserify -o iconv.js index.js


        and now you have browser version of iconv lite library (in iconv.js file) that will work from browser.



        With it you can run:



         document.getElementById('file').addEventListener('change', function(event) 
        var reader = new FileReader();
        reader.onload = function(event)
        var utf8_str = iconv.decode(Buffer.from(event.target.result), 'CP437');
        ;
        reader.readAsArrayBuffer(event.target.files[0]);
        );


        you will need to have:



        <input id="file" type="file" />


        and



        <meta charset="utf-8"/>


        so iconv-lite can convert string to utf-8, which is the only valid charset.






        share|improve this answer













        Encoding API is limited and don't support CP437. So the process of conversion look like this:



        create empty npm project using



        npm init


        then install



        npm install -g browserify
        npm install iconv-lite buffer-shims


        create index.js file with:



        window.iconv = require('iconv-lite');
        window.Buffer = require('buffer-shims');


        run



        browserify -o iconv.js index.js


        and now you have browser version of iconv lite library (in iconv.js file) that will work from browser.



        With it you can run:



         document.getElementById('file').addEventListener('change', function(event) 
        var reader = new FileReader();
        reader.onload = function(event)
        var utf8_str = iconv.decode(Buffer.from(event.target.result), 'CP437');
        ;
        reader.readAsArrayBuffer(event.target.files[0]);
        );


        you will need to have:



        <input id="file" type="file" />


        and



        <meta charset="utf-8"/>


        so iconv-lite can convert string to utf-8, which is the only valid charset.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 18:58









        jcubicjcubic

        34.3k30124227




        34.3k30124227





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315114%2fconvert-cp437-using-javascript-encoding-api-in-browser%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto