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

How to read stream of file in k6 #1002

Closed
d5gwsw opened this issue Apr 18, 2019 · 8 comments
Closed

How to read stream of file in k6 #1002

d5gwsw opened this issue Apr 18, 2019 · 8 comments
Labels

Comments

@d5gwsw
Copy link

d5gwsw commented Apr 18, 2019

No description provided.

@d5gwsw
Copy link
Author

d5gwsw commented Apr 18, 2019

In my project there is no .go file.Is there any other way to read the stream of file in k6 in simpler way.
I want to read stream of 1 MB pdf file and need to pass that stream to my api.

@mstoykov
Copy link
Contributor

I don't understand why you would need .go file - k6 IS written in Go but other than that no .go files are required.
There is no stream api for k6, but you can just read the whole file and send it as file over http if this is what you need. Please take a look at the http.file documentation although you can probably do it with only http.post.

@d5gwsw
Copy link
Author

d5gwsw commented Apr 18, 2019

Actually I want to pass the file stream to request body to my api. Later on this stream is used to further process
I was reffering
#612
but this is incomplete.

@mstoykov
Copy link
Contributor

What you want is to send that pdf over http to your api, correct? In that case what I have proposed will work for you.

The #612 PR was about reading big files in small parts .. unfortunately this would not work ... well in clustered execution and because of that was not merged.

@d5gwsw
Copy link
Author

d5gwsw commented Apr 24, 2019

I tried this but I am always getting unathorised error because API needs stream input & using http.file we are passing binary file.
Is there any other way to pass file stream?

@na--
Copy link
Member

na-- commented Apr 24, 2019

@d5gwsw, what exactly do you mean by a file stream? Can you tell me what HTTP feature/RFC you specifically need? Transfer-Encoding: chunked?

@d5gwsw
Copy link
Author

d5gwsw commented Apr 24, 2019

I need below input to my api. In without k6 I am using like this-
let filePath='D:\sample.pdf'
contentLength: fs.statSync(filePath).size,
contentType: 'applicaton/pdf',
stream: fs.createReadStream(filePath)

above code in typescript using node js.
k6 is not supporting fs.createReadStream.

stream should be like this which I am getting through above code without k6:=
'{"_readableState":{"objectMode":false,"highWaterMark":65536,"buffer":{"head":null,"tail":null,"length":0},' +
// '"length":0,"pipes":null,"pipesCount":0,"flowing":null,"ended":false,"endEmitted":false,"reading":false,"sync":true,' +
// '"needReadable":false,"emittedReadable":false,"readableListening":false,"resumeScheduled":false,"paused":true,"emitClose":false,' +
// '"destroyed":false,"defaultEncoding":"utf8","awaitDrain":0,"readingMore":false,"decoder":null,"encoding":null},' +
// '"readable":true,"_events":{},"_eventsCount":1,"path":"D:\Sample.pdf",' +
// '"fd":null,"flags":"r","mode":438,"end":null,"autoClose":true,"bytesRead":0,"closed":false}';

@na--
Copy link
Member

na-- commented Apr 25, 2019

I'm sorry, but k6 isn't built on top of Node.js and it doesn't support the Node.js APIs. Some JS libraries that rely on some node APIs may work when passed through browerify (more info), but usually not the ones that require access to the file system.

I don't know why in your case it's important to read the file as a stream, and why the open() function that k6 provides is insufficient, but you currently can't do that in k6. You can follow this issue to be informed when we introduce such functionality in k6: #592

Also, I'll close this issue, since the github issues are not the most appropriate place to ask "how to" questions. A much more appropriate place would be the community forum, or as you've found out, Stack Overflow. If you have a specific feature suggestion for k6, other than streaming reading of files, feel free to open a new issue.

@na-- na-- closed this as completed Apr 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants