-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Web: support other encodings than UTF-8 #79275
Comments
Is there any plan for this issue ? |
Webpack seems possible for
I used the following const path = require('path');
module.exports = {
entry: 'iconv-lite',
devtool: 'inline-source-map',
mode: 'production',
output: {
path: path.resolve(__dirname, 'lib'),
filename: 'iconv-lite-umd.js',
libraryTarget: 'umd',
globalObject: 'typeof self !== \'undefined\' ? self : this'
}
}; |
Hey, iconv-lite author here. The issue you mentioned should be fixed now (needs some more checking in other environments). As an additional benefit, the Streaming API should work in the browser if 'stream' module is included (or if enabled explicitly). Let me know if you have any questions about enabling it. I'm trying my best to keep the size to a minimum; in my measurements, with streams, iconv-lite takes ~320Kb minified by webpack (I just used webpack cli with default params). I guess 1Mb is the source map stuff. Would that be small enough for your purposes? |
@ashtuchkin thanks a lot for commenting here, I am planning to pick this up soon (coming months) and will report back to you how it goes 👍 |
Awesome, looking forward to it! |
Hello @bpasero! I am in desperate need of this feature, so I was thinking maybe it is a good opportunity for me to contribute. However currently I have zero knowledge about vscode codebase, so I decided it'd be good to verify it with you before diving in. Would you be open to this being an outside contribution? Do you think adding this feature is doable for the first time contributor? Would it be possible for you to provide me some guidance as which files/places in the project this relates to? |
Thanks for the offer, but not having fully understood yet how to approach this from the VSCode side makes this a bit harder for me to ask for help. I think there are a few steps towards the solution that maybe can be decoupled and worked on individually. I think we need a way to consume One thing not clear to me yet is how to get node.js streams into VSCode web, because we heavily depend on node.js streams for all encoding related things. I am not sold in having to use node.js streams so maybe an alternate solution is to convince The code for encoding handling lives in |
iconv-lite fully supports webpack (especially the 0.6 version I'm working on right now), so UMD package similar to semver-umd should work great. Before I release 0.6, please use master branch for now if you want to check it out. As for the streams - iconv-lite internally uses a simplified stream interface for all codecs that is also compatible with Node's StringDecoder class (but doesn't depend on it). Basically the interface is the following:
I'm wondering if that would help? |
Awesome, thank you! Looks like I have all the puzzle pieces. Will take a deeper look during the weekend. An opportunity to contribute to VSCode (which I have been happily using for 4 years) is very exciting :) |
@ashtuchkin does that mean I can pass in "something" that matches that interface and it will work? I would need this to be exposed from the TypeScript types of If that was changed, maybe VSCode could use its own stream helpers and not the node.js ones. |
I can add these methods (getEncoder and getDecoder) to typescript definition, currently they are not there. I was treating them as non-public for the time being as they are not usually useful for Node.js. I did get requests to make them public before, so it probably makes sense to just do it. The link you gave is for decodeStream/encodeStream - these are for Node.js streams, you're right. These are not what I was talking about.
It's the other way around: iconv-lite itself provides encoder/decoder objects with this interface and you can wrap it with your stream implementation/helpers to do the conversion. |
As an example, I'm wrapping these Encoder/Decoder stream objects with Node.js Transformer class to create Node.js-compatible transformer streams here https://github.com/ashtuchkin/iconv-lite/blob/master/lib/streams.js#L27 (this.conv is the Encoder) |
Added methods to .d.ts in the latest master commit (ashtuchkin/iconv-lite@4c3eff9). |
Hello @bpasero! I've taken a bit closer look into the source code and am thinking that I would really like to try to contribute this feature. However I totally understand that it is not something small and you might want to do it internally inside VSCode team. So I would kindly ask you to give me a chance here and champion me if it is at all possible. From my side I will try to split the work into smaller chunks to make it easier for you to review it and give your feedback. If at any point in time you will think that this collaboration isn't working for any reason, I'll step down. Here is my initial plan of how to complete the task:
How does this sound to you? |
Yeah that sounds good to me. The first step of removing node.js streams for all encoding matters and using our own streams VSCode provides that are web supported is a good starting point. Btw, we use another library Timing wise we are entering endgame next week, I will probably not have a lot of time to look into this until the week after next week, but feel free to create a PR for the first step. I even think the second step can be done too. For that purpose though I would go and create a (Microsoft owned) GH repository to host the UMD version of |
Good luck with upcoming release then. Seeing this small dot above the gear always makes me happy! Let's see how far I can get with the first step by the time you are done with Thanos :)
Hopefully it won't be a big deal. Will take a closer look during the process.
Sure, it absolutely makes sense. |
@ashtuchkin do you think you can make exposing getEncoder/getDecoder types a patch release for 0.5? This will allow the first part of my work to be independent from 0.6 release timeline. |
@gyzerok yeah makes sense, how would VSCode access this buffer shim? I think I want to be careful to only really use it for |
@gyzerok I think the best is to expose methods from the UMD Module that use Uint8Array and internally forward to iconv-lite as shimmed Buffer |
Not sure what you are asking here.
From types perspective we do not expose any details of the fact that any shim is used, because only |
@bpasero both Node.js Buffer and shim buffer extend So even if some code will use |
+1. Also for decoding, I'm 99% sure you can pass Uint8Array instead of Buffer and it'll work fine. |
@gyzerok yeah anything really works for me for as long as it stays isolated to |
Co-authored-by: Benjamin Pasero <[email protected]>
* move encoding.ts to common for #79275 * load iconv-lite-umd and jschardet in web version for #79275 * move EncodingOracle to the AbstractTextFileService for #79275 * review * update to new iconv-lite-umd * add workaround for jschardet types * fix indentation * add iconv-lite-umd and jschardet to workbench.html * fix paths for modules Co-authored-by: Benjamin Pasero <[email protected]>
@ashtuchkin while working further on the implementation I've discovered that there is one case, where Internally const iconv = require('iconv-lite-umd');
iconv.decode(Uint8Array.from([...iconv.encode('Lorem ipsum', 'utf16le')]), 'utf16le'); The easy way to fix it would be to change function InternalDecoder(options, codec) {
this.decoder = new StringDecoder(codec.enc);
}
InternalDecoder.prototype.write = function(buf) {
if (Buffer.isBuffer(buf)) {
return this.decoder.write(buf);
}
return this.decoder.write(Buffer.from(buf));
}
InternalDecoder.prototype.end = function() {
return this.decoder.end();
} Do you think this is an acceptable change for |
…ce for #79275 (#100804) * move encoding logic from NativeTextFileService to AbstractTextFileService for #79275 * some cleanup things - just cosmetic * fix tests * review * use correct comparison Co-authored-by: Benjamin Pasero <[email protected]>
Thanks @gyzerok for driving this from the VSCode side and @ashtuchkin for the |
I would like to also thank everyone envolved:
Love the open-source community! ❤️ |
Ideas: #79232
The text was updated successfully, but these errors were encountered: