Skip to content
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

decouple vs/base/node/encoding.ts from node streams for #79275 #99413

Merged
merged 1 commit into from
Jun 17, 2020
Merged

decouple vs/base/node/encoding.ts from node streams for #79275 #99413

merged 1 commit into from
Jun 17, 2020

Conversation

gyzerok
Copy link
Contributor

@gyzerok gyzerok commented Jun 5, 2020

This PR introduces the first piece of work which is needed to get #79275 done. It was agreed in advance that Benjamin Pasero will take care of the review here.

Not sure yet if we are going to keep all the future changes in this PR and merge them all at once or merge this PR and open more for next steps. It all depends on Benjamin to decide.

package.json Outdated
@@ -41,7 +41,7 @@
"graceful-fs": "4.2.3",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.3",
"iconv-lite": "0.5.0",
"iconv-lite": "ashtuchkin/iconv-lite#4c3eff9dac5c225f38500a633a0cfdc4ad6e0eb8",
Copy link
Contributor Author

@gyzerok gyzerok Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to do it temporarily, so the types of iconv.getDecoder/iconv.getEncoder are there. However I believe we will change it before merging.

There are couple of routes we can take here:

  1. Use iconv-lite-umd module, which will have correct type definitions.
  2. Since the APIs are there and only types are not, we can temporarily use as ... with our own type definitions.

Personally I prefer option 1.

Update
Since iconv-lite 0.6.0 got release, I've updated here to use it.

}

async function readAllAsString(stream: streams.ReadableStream<string>) {
return streams.consumeStream(stream, strings => strings.join(''));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit offtopic:

I was wondering why do you have to pass reducer to consumeStream? It is already being passed on stream creation. Why not reuse it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gyzerok we still need the reducer because consumeStream is generic, right? Or would you suggest to have the reducer be accessible from the stream to reuse it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking more conceptually, not from the types perspective. At least from my point of view it makes sense to change it so, that the reducer passed on the creation is reused. I assume it can either be done by either making consumeStream a method of ReadableStream or by making reducer accessible.

Anyway, consider it more as a suggestion from the "new to the project" person perspective :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying very hard to have as little methods on the stream as possible to allow for easy inter-op with e.g. node.js or any other stream interface. So I do not want to push too many things onto it.

encoding: UTF8 // very important, so that strings are passed around and not buffers!
});
const snapshot = typeof value === 'string' ? stringToSnapshot(value) : value;
return toEncodeReadable(snapshot, encoding, { addBOM });
Copy link
Contributor Author

@gyzerok gyzerok Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ITextSnapshot interface here does match Readable (but does not implement it). Is it accidental or intentional?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gyzerok historically the ITextSnapshot interface was first and then I added Readable, I think it is fine to leave it since TS takes care of understanding the interface is implemented by structural type-check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if it makes sense to separately change the code so that ITextSnapshot implements Readable. Not as part of this change, but in general. Otherwise thanks for the explanation!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine like this given TS takes care, but thanks for noting.

@bpasero bpasero self-assigned this Jun 5, 2020
@bpasero bpasero added this to the June 2020 milestone Jun 5, 2020
@bpasero bpasero merged commit 1dbfecd into microsoft:master Jun 17, 2020
bpasero added a commit that referenced this pull request Jun 17, 2020
bpasero added a commit that referenced this pull request Jun 17, 2020
@bpasero
Copy link
Member

bpasero commented Jun 17, 2020

I merged the wrong PR.........

@bpasero
Copy link
Member

bpasero commented Jun 17, 2020

@gyzerok sorry for that, I am not entirely sure how to restore this PR, can you maybe do a new one from your branch? I will meanwhile review your changes and then can give feedback

@bpasero
Copy link
Member

bpasero commented Jun 17, 2020

@gyzerok nevermind, this PR is incredibly well done given the complexity of the matter. I will push your changes to master and then push a change on top with some changes that I think are still needed and ping you on those changes and explain why I did them.

The next step I guess is to flip to iconv-lite-umd 👍

bpasero added a commit that referenced this pull request Jun 17, 2020
@gyzerok
Copy link
Contributor Author

gyzerok commented Jun 17, 2020

@bpasero thanks for the kind words!

I think I can go with migrating to iconv-lite-umd and making the first step from the next steps plan. What do you think?

@bpasero
Copy link
Member

bpasero commented Jun 17, 2020

@gyzerok yeah I think you outlined it well, to summarise with my own words: all of the encoding related code within native text file service should move up to the AbstractTextFileService that is shared with web. I expect the native text file service to then only have little code, e.g. to support the "write as admin" feature and what looks like some dependencies on chmod and file stats.

We can also think about doing the encoding guessing as an independent step and leaving it as something the native service could pass over. Up to you.

As I mentioned in #79275 (comment), I still think the dependency to Buffer is something to clean up to be able to use this in web.

@gyzerok gyzerok deleted the docuple-encoding-from-node-streams branch June 17, 2020 10:33
@github-actions github-actions bot locked and limited conversation to collaborators Aug 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants