-
Notifications
You must be signed in to change notification settings - Fork 640
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
Conversation
bytes/bytes_test.ts
Outdated
); | ||
assertEqual(i, 2); | ||
}); | ||
test(function testFindLastIndex() { |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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 @@ | |||
{ |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
multipart/multipart_test.ts
Outdated
assertEqual(n, 3); | ||
assertEqual(err, "EOF"); | ||
}); | ||
test(function testScanUntilBoundary4() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 : )
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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[] = []; |
There was a problem hiding this comment.
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
|
bar | ||
----------------------------434049563556637648550474 | ||
content-disposition: form-data; name="file"; filename="tsconfig.json" | ||
content-type: application/octet-stream |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs tests though.
There was a problem hiding this 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
@ry review applied. And there are additional changes about
|
} | ||
|
||
/** Reader utility for combining multiple readers */ | ||
export class MultiReader implements Reader { |
There was a problem hiding this comment.
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 : )
There was a problem hiding this 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 : )
about
stringsRerader
andStringReader
stringsReader()
is factory ofBuffer
Buffer
bufio_test.ts
failedBufReader#readBytes
always returns -1 if data read has finished by first readBufreader
's bug orStringReader
's bug