Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
Javascript encoding problem when downloading files

I have a page which converts images to ANSI colored batch console art, with a download button, but it gives errors when I open it. In notepad I noticed it says "Unix (LF)" on the bottom right corner. All my other batch scripts are "Windows (CRLF)". How can I encode it to the correct format? Is that the problem?

example from the batch (one pixel is one █ character, ESC is the ANSI escape character):

@echo off
chcp 65001 >nul
cls

echo ESC[38;2;21;20;26m█ESC[38;2;21;20;26m█

...

pause >nul

enter image description here

Those are the errors. It works perfectly when I paste the code into a new .bat file so it's definitely some sort of encoding problem.

The js that handles the download:

var dwn = $('#download') // Download button

dwn.download = 'console-img.bat'
dwn.href = URL.createObjectURL(new Blob([result], { type: 'text/plain' }))

// result is a string containing the code
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Okay, after a bit of researching about CRLF / LF I found the solution.

Replace all the \n in your string to \r\n

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda