GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||
GeezerVison is showing github.com — fs: work with any TypedArrays instead of only Uint8Arrays by SirR4T · Pull Request #22150 · nodejs/node Conversation
|
|
cc: @TimothyGu So, i'm not 100% sure what behaviour should be expected, when writing and reading to and from files, using TypedArrays. For instance, const input = Uint8Array.from(Buffer.from(s, 'utf8')); with any other |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
a53af6e to
5204651
Compare
|
We need tests to make sure it's handled correctly on the C++ side |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actually, reading this again tests are missing - if we officially support those types we need to make sure we have tests making sure we don't break that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
If you haven't wrote tests for PRs before and want help with writing the tests or aren't sure what/where to do let me know and I'll elaborate on how that works. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@benjamingr I'm happy to write tests, but I'm not sure what the behaviour should be, when writing to files via TypedArrays or reading from them. Hence the hesitation. Maybe I could make copies of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@SirR4T basically, to check that you can perform each FS operations that supports other types of arrays and that it returns the value you expect - |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
5204651 to
ae2d513
Compare
That is because const a = new Uint8Array([1, 2, 3]) // In memory: 0x01 0x02 0x03 const b = Uint16Array.from(a); // In memory 0x0001 0x0002 0x0003 However, if the test doesn't work with For testing, you could use |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Also, I'd be fine if you modify existing tests rather than creating new ones. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
ae2d513 to
bcaacaa
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@benjamingr : going ahead with @TimothyGu 's suggestion, modifying the existing test case.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@benjamingr this test is currently failing with
assert.js:84
throw new AssertionError(obj);
^
AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
+ actual - expected ... Lines skipped
Int8Array [
+ 45,
+ 50,
+ 55,
+ 44,
+ 45,
+ 49,
+ 49,
+ 53,
+ 44,
+ 45,
...
- -27,
- -115,
- -105,
- -24,
- -74,
- -118,
- -27,
- -101,
- -67,
- -26,
...
What am i doing wrong?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@TimothyGu makes sense, going ahead with the current test case. Will modify the test case name too. Currently, it is failing with I notice that:
Can't shake the feeling i'm doing something terribly wrong here. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
bcaacaa to
bc3b58e
Compare
|
@TimothyGu @benjamingr : The file contents are a string of numbers (positive and negative), concatenated by |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hope this answers your question.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
fs.readFileSync(..., 'utf8') returns a string, so the assertion should compare with s.repeat(8) instead.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
ah! indeed. so that will work for reads that are string based, that is, for utf8 strings, Buffers, Uint8Arrays. How should I test for the other typed arrays and data views?
For instance, when encoding is not specified fs.readFileSync() returns a Buffer. How do i match this with Int8Arrays or other typed arrays?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You don't. The test is testing if writeFile supports non-Buffer TypedArrays. It's not testing readFileSync, and you should always compare the result of readFileSync to the string.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
aha! things are much more clearer now, thanks for the explanation 😄
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment explaining why .repeat(8) is necessary? Specifically, that getArrayBufferViews expects it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Could you please rebase this branch on master? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@benjamingr tests added, and now passing. @TimothyGu I can see that this diff of my feature branch against upstream/master is showing the correct files changed, but this PR is showing many more commits. How do I fix this? Should I close this and raise a different PR? This is after rebasing against latest upstream master. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@SirR4T I see that your branch has this merge commit: SirR4T@590d218 You would need to get rid of that merge commit for things to work. I think just doing a |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
590d218 to
0b78626
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You should probably use https://github.com/nodejs/node/blob/master/lib/internal/util/types.js#L22 here and later.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
good idea, will do that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think we just use console.log in tests, don't we?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
oh... I'm not sure what the current convention is, but following the discussion at #9314, I had assumed debug log was the consensus. Lemme know if I should change to console.log.
If I understand correctly, console.log statements are not printed when tests are run, but debuglog statements are printed atleast when tests fail.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM once @lundibundi's comments are addressed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@SirR4T seems like the CI is failing on the new test. Could you take a look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Should this be backported to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The conflict is trivial. I have a good version of this change locally. Currently compiling/running tests. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
PR-URL: #22150 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
Using the same filename for different async tests could lead to race conditions. Example failure: https://travis-ci.com/nodejs/node/jobs/143351655 Refs: nodejs#22150
Using the same filename for different async tests could lead to race conditions. Example failure: https://travis-ci.com/nodejs/node/jobs/143351655 Refs: #22150 PR-URL: #22659 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]>
PR-URL: #22150 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
Using the same filename for different async tests could lead to race conditions. Example failure: https://travis-ci.com/nodejs/node/jobs/143351655 Refs: #22150 PR-URL: #22659 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]>
Notable changes:
* child_process:
* `TypedArray` and `DataView` values are now accepted as input by
`execFileSync` and `spawnSync`. #22409
* coverage:
* Native V8 code coverage information can now be output to disk by setting the
environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
* The bundled npm was upgraded to version 6.4.1. #22591
* Changelogs:
[6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
[6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
[6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
[6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
* The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
`fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
`DataView` objects. #22150
* A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
`fs.readdirSync`. If set to true, the methods return an array of directory
entries. These are objects that can be used to determine the type of each
entry and filter them based on that without calling `fs.stat`. #22020
* http2:
* The `http2` module is no longer experimental. #22466
* os:
* Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
manipulate the scheduling priority of processes. #22394
* process:
* Added `process.allowedNodeEnvironmentFlags`. This object can be used to
programmatically validate and list flags that are allowed in the
`NODE_OPTIONS` environment variable. #19335
* src:
* Deprecated option variables in public C++ API. #22392
* Refactored options parsing. #22392
* vm:
* Added `vm.compileFunction`, a method to create new JavaScript functions from
a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
* [lundibundi](https://github.com/lundibundi) - Denys Otrishko
PR-URL: #22716
PR-URL: #22150 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
Using the same filename for different async tests could lead to race conditions. Example failure: https://travis-ci.com/nodejs/node/jobs/143351655 Refs: #22150 PR-URL: #22659 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]>
Notable changes:
* child_process:
* `TypedArray` and `DataView` values are now accepted as input by
`execFileSync` and `spawnSync`. #22409
* coverage:
* Native V8 code coverage information can now be output to disk by setting the
environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
* The bundled npm was upgraded to version 6.4.1. #22591
* Changelogs:
[6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
[6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
[6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
[6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
* The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
`fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
`DataView` objects. #22150
* A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
`fs.readdirSync`. If set to true, the methods return an array of directory
entries. These are objects that can be used to determine the type of each
entry and filter them based on that without calling `fs.stat`. #22020
* http2:
* The `http2` module is no longer experimental. #22466
* os:
* Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
manipulate the scheduling priority of processes. #22407
* process:
* Added `process.allowedNodeEnvironmentFlags`. This object can be used to
programmatically validate and list flags that are allowed in the
`NODE_OPTIONS` environment variable. #19335
* src:
* Deprecated option variables in public C++ API. #22515
* Refactored options parsing. #22392
* vm:
* Added `vm.compileFunction`, a method to create new JavaScript functions from
a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
* [lundibundi](https://github.com/lundibundi) - Denys Otrishko
PR-URL: #22716
Notable changes:
* child_process:
* `TypedArray` and `DataView` values are now accepted as input by
`execFileSync` and `spawnSync`. #22409
* coverage:
* Native V8 code coverage information can now be output to disk by setting the
environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
* The bundled npm was upgraded to version 6.4.1. #22591
* Changelogs:
[6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
[6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
[6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
[6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
* The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
`fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
`DataView` objects. #22150
* A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
`fs.readdirSync`. If set to true, the methods return an array of directory
entries. These are objects that can be used to determine the type of each
entry and filter them based on that without calling `fs.stat`. #22020
* http2:
* The `http2` module is no longer experimental. #22466
* os:
* Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
manipulate the scheduling priority of processes. #22407
* process:
* Added `process.allowedNodeEnvironmentFlags`. This object can be used to
programmatically validate and list flags that are allowed in the
`NODE_OPTIONS` environment variable. #19335
* src:
* Deprecated option variables in public C++ API. #22515
* Refactored options parsing. #22392
* vm:
* Added `vm.compileFunction`, a method to create new JavaScript functions from
a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
* [lundibundi](https://github.com/lundibundi) - Denys Otrishko
PR-URL: #22716
Notable changes:
* child_process:
* `TypedArray` and `DataView` values are now accepted as input by
`execFileSync` and `spawnSync`. #22409
* coverage:
* Native V8 code coverage information can now be output to disk by setting the
environment variable `NODE_V8_COVERAGE` to a directory. #22527
* deps:
* The bundled npm was upgraded to version 6.4.1. #22591
* Changelogs:
[6.3.0-next.0](https://github.com/npm/cli/releases/tag/v6.3.0-next.0)
[6.3.0](https://github.com/npm/cli/releases/tag/v6.3.0)
[6.4.0](https://github.com/npm/cli/releases/tag/v6.4.0)
[6.4.1](https://github.com/npm/cli/releases/tag/v6.4.1)
* fs:
* The methods `fs.read`, `fs.readSync`, `fs.write`, `fs.writeSync`,
`fs.writeFile` and `fs.writeFileSync` now all accept `TypedArray` and
`DataView` objects. #22150
* A new boolean option, `withFileTypes`, can be passed to to `fs.readdir` and
`fs.readdirSync`. If set to true, the methods return an array of directory
entries. These are objects that can be used to determine the type of each
entry and filter them based on that without calling `fs.stat`. #22020
* http2:
* The `http2` module is no longer experimental. #22466
* os:
* Added two new methods: `os.getPriority` and `os.setPriority`, allowing to
manipulate the scheduling priority of processes. #22407
* process:
* Added `process.allowedNodeEnvironmentFlags`. This object can be used to
programmatically validate and list flags that are allowed in the
`NODE_OPTIONS` environment variable. #19335
* src:
* Deprecated option variables in public C++ API. #22515
* Refactored options parsing. #22392
* vm:
* Added `vm.compileFunction`, a method to create new JavaScript functions from
a source body, with options similar to those of the other `vm` methods. #21571
* Added new collaborators:
* [lundibundi](https://github.com/lundibundi) - Denys Otrishko
PR-URL: #22716
|
Does this also affect |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.