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

Can fs.createReadStream() be used with assets #775

Closed
nevf opened this issue Jan 12, 2016 · 9 comments
Closed

Can fs.createReadStream() be used with assets #775

nevf opened this issue Jan 12, 2016 · 9 comments

Comments

@nevf
Copy link

nevf commented Jan 12, 2016

Can someone please let me know if fs.createReadStream() can be used with files in assets. My jx app is failing using it.

I've read "Accessing Files and Assets from a Package" at http://jxcore.com/docs/jxcore-feature-packaging-code-protection.html which suggests it can't be. And I've also read #77 which suggests it can. So I'm a bit confused.

@obastemur
Copy link
Member

Are you trying to read source files ? (.js) ? If so, add "fs_reach_sources": true to jxp file.

@nevf
Copy link
Author

nevf commented Jan 12, 2016

They are .html & .css files.`"fs_reach_sources": true`` is set. And the file path is absolute.

@ktrzeciaknubisa
Copy link
Member

@nevf Are you having problems with fs.createReadStream() for assets? Although it is not mentioned explicitly in the docs, it should work. We even have a test cases for this, e.g. test/jxcore/test-assets-fs-createReadStream.js . Why don't you try and let us know in case of some problems?

@nevf
Copy link
Author

nevf commented Jan 12, 2016

@ktrzeciaknubisa Yes I am having a problem as I mentioned in my first post. I am using node-static https://github.com/cloudhead/node-static which uses createReadStream() and it is failing.

Before I spent time debugging I wanted to know if createReadStream() should work. I'll reply again once I work out where it is going wrong.

@nevf
Copy link
Author

nevf commented Jan 12, 2016

Ok, got it. node-static chains event handlers as follows:

            fs.createReadStream(file, {
                flags: 'r',
                mode: 0666,
                start: startByte,
                end: startByte + (buffer.length ? buffer.length - 1 : 0)
            }).on('data', function (chunk) {
                // Bounds check the incoming chunk and offset, as copying
                // a buffer from an invalid offset will throw an error and crash
                if (chunk.length && offset < buffer.length && offset >= 0) {
                    chunk.copy(buffer, offset);
                    offset += chunk.length;
                }
            }).on('close', function () {
                streamFile(files, offset);
            }).on('error', function (err) {
                callback(err);
                console.error(err);
            }).pipe(res, { end: false });

If I remove the .on chains and use stream.on() it works. Otherwise I get cannot call undefined of on. So this appears as an api inconsistency with node.js?

@obastemur
Copy link
Member

@nevf can you grab 0.3.1.1 / compile and test if it works for you ? d28d6c5 should fix the problem.

@nevf
Copy link
Author

nevf commented Jan 13, 2016

@obastemur Yes that fixes it. Thank you for the very quick fix.

Can I just confirm that all I need is the new jx.exe, not other libraries, files etc.?

@obastemur
Copy link
Member

Can I just confirm that all I need is the new jx.exe, not other libraries, files etc.?

exactly

@obastemur
Copy link
Member

@nevf Thanks for the details. Closing this issue then.

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

No branches or pull requests

3 participants