-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
Allow using alternate sources of files #160
Comments
This sounds like my main concern with just accepting |
Documentation is easy, the hard part is deciding on the requirements. The concern about having to increase the major version if more of
|
So we are intending to implement #122 to resolve a race condition which is definitively a planned change to the fs API usage currently. I think there is another open issue to use another new part of the fs API as well. When a new major version gets cut, that becomes a larger burden because the Express.js project exposes this module as a core piece. That would that Express.js would also have to bump the major to use it and of course would mean maintaining the prior major version of this module for the LTS lifetime of the corresponding Express (which is that the prior major version of Express is supported for 1 year after a new major is released). Obviously this will happen, but it would be awesome if it doesn't require the frequency of majors to be more than one per year (which is how Node.js itself functions). As for marking as experimental, I'm not quite sure I'm following there. Should we match how Node.js does it and make it inaccessible unless node is started with a specific command line flag? |
By experimental I meant like Node.js which enables some experimental features without a flag (e.g. currently
There's also the third option which is probably the easiest for everyone involved. Since having an in-memory version of |
@LynnKirby So is there any progress on that? |
* Enables configuration to specify which file system to use to send files by default. Default: standard node js fs module (require('fs')) * Provides basic tests via global injection
* Enables configuration to specify which file system to use to send files by default. Default: standard node js fs module (require('fs')) * Provides basic tests via global injection
* Enables configuration to specify which file system to use to send files by default. Default: standard node js fs module (require('fs')) * Provides basic tests via global injection
* Enables configuration to specify which file system to use to send files by default. Default: standard node js fs module (require('fs')) * Provides basic tests via global injection
* Adds new option to specify which file system to use to serve files by default. * Adds exported erros for basic file system interface check * Provides basic tests via global injection
* Adds new option to specify which file system to use to serve files by default. * Adds exported erros for basic file system interface check * Provides basic tests via global injection
* Adds new option to specify which file system to use to serve files by default. * Adds exported erros for basic file system interface check * Provides basic tests via global injection
@hinell As in prior discussion I think it would be safer to create forks of these projects instead of parameterizing them or adding a switch for memory-fs. I rarely use them so I have no interest in maintaining such forks; I just use my own privately. |
* Add: new option to specify which file system to use to serve files by default. * Add: exported erros for basic file system interface check * Add: basic tests via global injection
* Add: new option to specify which file system to use to serve files by default. * Add: exported erros for basic file system interface check * Add: basic tests via global injection
I have a similar use case: I want to serve a One could argue that this is different enough to justify an entirely separate package (there's not From my perspective, an API like this would be ideal: const buf = Buffer.from('data i want to serve', 'utf8')
send(req, '/some-data', {
getStat: (path, cb) => cb(null, {mtime: 1234}),
getData: (offset, bytes) => {
const readable = new require('stream').Readable()
readable.push(buf)
readable.push(null)
return readable
}
}) I can understand though that, from the Express perspective, this is not worth maintaining. |
@derhuerst If you are interested, I developed a package named send-stream that can do it this way for express: const express = require("express");
const stream = require("stream");
const sendStream = require("send-stream");
class CustomStorage extends sendStream.Storage {
async open(data) {
return {
attachedData: data.buffer,
mtimeMs: data.mtimeMs,
size: data.buffer.byteLength
};
}
createReadableStream(storageInfo, range, autoClose) {
const buffer = range
? storageInfo.attachedData.subarray(range.start, range.end + 1)
: storageInfo.attachedData;
return new stream.Readable({
autoDestroy: autoClose,
read() {
this.push(buffer);
this.push(null);
}
});
}
async close() {
// noop
}
}
const storage = new CustomStorage();
const app = express();
const buf = Buffer.from('data i want to serve', 'utf8');
const mtimeMs = Date.now();
app.get('/some-data', async (req, res, next) => {
try {
await storage.send({ buffer: buf, mtimeMs: mtimeMs }, req, res);
}
catch (err) {
next(err);
}
});
app.listen(3000, () => {
console.info('listening on http://localhost:3000');
}); |
@nicolashenry Oh damn, we implemented basically the same twice. I ended up wrapping and monkey-patching (instead of forking) |
@derhuerst My main objective with the send-stream package was to implement some features missing in |
It would be useful to abstract the filesystem API so that, for example, in-memory files can be served.
I have a proof-of-concept (or even solution?) at 6c87c36. It adds an
fs
property to the options which requiresfs.stat
andfs.createReadStream
functions. Set the environment variableUSE_MEMFS
before running tests and the test will use memfs. memory-fs doesn't work because thefs.Stats
objects it creates only has functions attached and not all of the usual properties.Related: expressjs/serve-static#83
The text was updated successfully, but these errors were encountered: