Giter Club home page Giter Club logo

Comments (14)

Jacob-Christian-Munch-Andersen avatar Jacob-Christian-Munch-Andersen commented on May 11, 2024

Exactly what are you trying to do? The library has no native support for charsets other than UTF-8 and a basic ASCII encoding, if you want to use a different encoding you must make the transformation yourself.

from zip.js.

beshkenadze avatar beshkenadze commented on May 11, 2024

I get it. It seems the problem is not solved by JS :(

from zip.js.

Jacob-Christian-Munch-Andersen avatar Jacob-Christian-Munch-Andersen commented on May 11, 2024

The best solution is usually to use UTF-8 all the way through, if that is not an option, for instance because an external source provide data in a different format you'll have to write a converter. It's not that difficult, you just need a table of the Unicode values of the 256 characters in CP1251: http://en.wikipedia.org/wiki/Cp1251

For instance when you find the character with code 192 you should convert it to 0x410 (1040 in decimal), and so forth.

from zip.js.

beshkenadze avatar beshkenadze commented on May 11, 2024

The problem is that not always the file will be in cp1251, it can be in other encodings, but thanks for the answer!

from zip.js.

gildas-lormeau avatar gildas-lormeau commented on May 11, 2024

Yes Jacob is right, zip.js can't support all encodings because it's beyond its scope. The right option here is to write your own Reader and Writer constructors instead of using TextReader/TextWriter.

from zip.js.

gildas-lormeau avatar gildas-lormeau commented on May 11, 2024

Actually, I am wrong, there's maybe a fix (for file data) by using FileReader#readAsText 2nd parameter...

from zip.js.

beshkenadze avatar beshkenadze commented on May 11, 2024

I will try

from zip.js.

gildas-lormeau avatar gildas-lormeau commented on May 11, 2024

Thanks!

from zip.js.

beshkenadze avatar beshkenadze commented on May 11, 2024

Thanks for the help! Work, but not for zip.js :)
zip.js gives me already broken text.
I've used https://code.google.com/p/bitjs he gives data in Uint8Array, I've read with readAsText (bb, 'cp1251') and this work!

from zip.js.

gildas-lormeau avatar gildas-lormeau commented on May 11, 2024

I think I just have to change the TextWriter constructor signature to accept a new encoding parameter and add the optional parameter here and it should be ok in zip.js :).

from zip.js.

beshkenadze avatar beshkenadze commented on May 11, 2024

Thanks! :)

from zip.js.

beshkenadze avatar beshkenadze commented on May 11, 2024

Hi!
The problem is solved for BlobReader, but when using HttpReader problem persists.
Why not use in HttpReader:
var dataView = new DataView(request.response);
that.data = new Blob([dataView], {type: request.getResponseHeader("Content-Type")});
and use as BlobReader?

And it may be need to add an additional parameter to the "charset" TextWriter to specify the encoding, and use like this? :
if(typeof charset != "undefined")
reader.readAsText(blob, charset);
else
reader.readAsText(blob);

from zip.js.

gildas-lormeau avatar gildas-lormeau commented on May 11, 2024

Hi :)

I may be missing something here but I don't really what's wrong with the current implementation of HttpReader constructor. There are 2 main use cases when using it:

  • reading a zip file to uncompress : it's the zip binary data so the charset is not an issue
  • reading a text file (or binary file) to compress : it may be a text file but it's also read as binary data because there is no need to read it as text when compressing it

Could you explain me when using "Content-Type" header is really useful?

from zip.js.

beshkenadze avatar beshkenadze commented on May 11, 2024

reading a zip file to uncompress : it's the zip binary data so the charset is not an issue

There is no easy way to convert the encoding but to specify when readAsText.

Could you explain me when using "Content-Type" header is really useful?

Content-Type is not strictly required (in zip.js), but improves the semantics.
And "DataView & Blob" does not apply to the Content-type, but "DataView & Blob" method to receive file from the network.

from zip.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.