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

feat: multipart, etc.. #180

Merged
merged 13 commits into from
Feb 10, 2019
Merged

feat: multipart, etc.. #180

merged 13 commits into from
Feb 10, 2019

Conversation

keroxp
Copy link
Contributor

@keroxp keroxp commented Feb 8, 2019

  • added multipart module that read/write multipart/form-data
  • added some related modules
  • formated

about stringsRerader and StringReader

  • currently stringsReader() is factory of Buffer
  • I implemented another version of it without Buffer
  • It looks fine but bufio_test.ts failed
  • It seems that BufReader#readBytes always returns -1 if data read has finished by first read
    • I don't know whether It is Bufreader's bug or StringReader's bug

);
assertEqual(i, 2);
});
test(function testFindLastIndex() {
Copy link
Member

Choose a reason for hiding this comment

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

please have blank line between test cases.

Don't prefix test cases with "test" but use "bytes" ... EG "bytesFindLastIndex"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, but is there prettier rule for that ?

tsconfig.json Outdated
@@ -0,0 +1,9 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

Don't add this file. Even if it's needed, we need to think thru the details of adding tsconfig.json (which we haven't)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

assertEqual(n, 3);
assertEqual(err, "EOF");
});
test(function testScanUntilBoundary4() {
Copy link
Member

Choose a reason for hiding this comment

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

Rename this tests and others: multipartScanUntilBoundary4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Copy link
Contributor

@kitsonk kitsonk left a comment

Choose a reason for hiding this comment

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

A few comments

@@ -0,0 +1,4 @@
.DS_Store
Copy link
Contributor

Choose a reason for hiding this comment

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

All of these should simple not be committed, you can add .DS_Store to your global git config and the rest have no legitimate reason to be included.

Copy link
Contributor Author

@keroxp keroxp Feb 9, 2019

Choose a reason for hiding this comment

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

I disagree. Why don't we have .gitignore? It's actually common.

Copy link
Member

Choose a reason for hiding this comment

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

It's fine with me - .gitignore is cheap

Copy link
Contributor

Choose a reason for hiding this comment

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

It maybe cheap, but why don't we have these developer unique ignores in Deno then?

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with that in Deno too shrug

@@ -0,0 +1,54 @@
export function bytesFindIndex(a: Uint8Array, pat: Uint8Array): number {
Copy link
Contributor

Choose a reason for hiding this comment

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

There really should be some sort of JSDoc.

bytes/bytes.ts Outdated
const s = pat[0];
for (let i = 0; i < a.length; i++) {
if (a[i] !== s) continue;
let pin = i;
Copy link
Contributor

Choose a reason for hiding this comment

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

pin is not reassigned, should be const

Copy link
Member

Choose a reason for hiding this comment

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

We need tslint in deno_std...

bytes/bytes.ts Outdated
const e = pat[pat.length - 1];
for (let i = a.length - 1; i >= 0; i--) {
if (a[i] !== e) continue;
let pin = i;
Copy link
Contributor

Choose a reason for hiding this comment

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

pin is not reassigned, should be const

const encoder = new TextEncoder();

export class StringReader implements Reader {
private offs = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use the _ sigil to preface private members.

Copy link
Contributor Author

@keroxp keroxp Feb 9, 2019

Choose a reason for hiding this comment

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

We don't have any convention about naming of private members. IMO, _ is redundant if there are no special reason.

Copy link
Member

Choose a reason for hiding this comment

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

Ya... we need to decide one way or another at some point on this. We've got code that does both. Obviously @kitsonk is on the side of _ ... I don't particularly care as long as its uniform ... I think we need a style guide PR and the ensuing blood bath discussion to figure it out : )

Copy link
Contributor

Choose a reason for hiding this comment

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

I have argued multiple times, there are two special reasons. To which no one has had an argument against.

  • On TypeScript private members take up a slot on the API surface, because they aren't really private. So you could be squatting on something semantically meaningful in a subclass. While this is likely rare in practice, it is still good form.
  • When private members do arrive, they will use the # sigil. To use them, we have to refactor at both the declaration and call site. Using _ means easier refactoring down the road.

Plus there is that it has been a common convention for a long long time and it makes the intent at the call site more clear, that you are accessing a private member.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyway, those discussion should not be concluded at here. Let's have discussion on another issue.

io/ioutil.ts Outdated
import { Reader, Writer } from "deno";
import { assert } from "../testing/mod.ts";

/* copy N size at the most. If read size is lesser than N, then returns nread */
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be JSDoc /**

io/util.ts Outdated
postfix?: string;
} = { prefix: "", postfix: "" }
): Promise<{ file: File; filepath: string }> {
const r = ~~(Math.random() * 1000000);
Copy link
Contributor

Choose a reason for hiding this comment

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

feels a bit strange to me... the double bitwise operator... at the least it is unclear... while I am not rejecting it, it does feel like it temporary files are something that Deno itself should be handling. Especially because there is no contract here to purge it.

@ry it feels like a tempfile is something that runtime users should be abstracted from.

Copy link
Member

Choose a reason for hiding this comment

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

@keroxp I agree that the double ~ needs a comment - I don't know what that's doing.

This feels like a function that can be moved into a common utility module at some point (or even into core) but I think for now let's just land it here.

Copy link
Member

Choose a reason for hiding this comment

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

I believe it gets rid of decimal part of number, ie. ~~1.23456 === 1

Copy link
Member

Choose a reason for hiding this comment

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

I see. I'd prefer if @keroxp uses Math.floor() then as it's more readable.

io/writers.ts Outdated
@@ -0,0 +1,37 @@
import { Writer } from "deno";

const e = new TextEncoder();
Copy link
Contributor

Choose a reason for hiding this comment

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

would prefer encoder and decoder, we don't need to be human minifiers.

const e = new TextEncoder();
const d = new TextDecoder();
export class StringWriter implements Writer {
private chunks: Uint8Array[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

again, private memers should start with a _ sigil

@keroxp
Copy link
Contributor Author

keroxp commented Feb 9, 2019

  • Added JSDoc comment for newly added resources.
  • placed shared TextEncoder and TextDecoder instances on strings/strings.ts

bar
----------------------------434049563556637648550474
content-disposition: form-data; name="file"; filename="tsconfig.json"
content-type: application/octet-stream
Copy link
Member

Choose a reason for hiding this comment

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

Nice tests!

export const encoder = new TextEncoder();

/** Shorthand for new TextEncoder().encode() */
export function encode(input?: string): Uint8Array {
Copy link
Member

Choose a reason for hiding this comment

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

Sure. I guess this is useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

Needs tests though.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

This is great functionality to have. Just one nit about the double tilde and then we can land.

- Changed return type of `MultipartReader.readForm()` to map of string | FormFile
- This is because deno's FormData can only accept string or instance of DenoBlob
- Added more tests about MultipartReadre and tempFile
@keroxp
Copy link
Contributor Author

keroxp commented Feb 10, 2019

@ry review applied. And there are additional changes about readForm result. This is because:

  • deno's FormData can't accept field value except string or DenoBlob
  • DenoBlob is not suitable for form file value
    • Blob is designed for immutable, in-memory data

}

/** Reader utility for combining multiple readers */
export class MultiReader implements Reader {
Copy link
Member

@ry ry Feb 10, 2019

Choose a reason for hiding this comment

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

Yes! I like it when we copy Go : )

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM

In the future please go through can click "Resolve Comment" - it makes it easier to skim comments : )

@ry ry merged commit fda9c98 into denoland:master Feb 10, 2019
ry pushed a commit to ry/deno that referenced this pull request Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants