GithubHelp home page GithubHelp logo

liviamedeiros / poteto Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 1.0 211 KB

poteto is HTTP-alike fetch for FILE protocol, e.g. fetch('file:///usr/bin/node')

Home Page: https://www.npmjs.com/package/poteto

License: GNU General Public License v3.0

JavaScript 100.00%
fetch file fs url nodejs http polyfill ponyfill

poteto's People

Stargazers

 avatar

Watchers

 avatar

poteto's Issues

Deno support

For initial compatibility with Deno, the following incompatibilities with Node.js API have to be solved:

  • fs.writeFile(_, body, _) doesn't accept ReadableStream as body
  • fd.write(chunk, { length, position } signature is not supported
  • filehandle[Symbol.asyncDispose] is not defined
  • Request instance properties, integrity in particular, are ignored by constructor and fetch (which is security issue tbh)
  • ReadableStream.from() is not implemented (tbf it's too fresh)
  • fd.read() signature is... I don't get it rn
  • fs.fileAppend(_, body, _) doesn't accept ReadableStream as body either
  • fd.readableWebStream() is not supported

HTTP `Range` header

The Range header has good potential for reading local files, but it's limited (only bytes is supported) and multipart/byteranges response format is clunky.

Perhaps it would make sense to deviate from standard here, providing a single response with all chunks concatenated, and introducing more units (maybe lines?).

HTTP headers that may be added

Some HTTP mechanisms that may be added:

  • Accept / Content-Type
    Implemented for errors.
    Easy to implement for arbitrary files by checking extension and/or using libmagic, but it's a guessing game.
  • Accept-Encoding / Content-Encoding
    Compression. This would be fun to have and it should be implemented, but the practical benefit too questionable.
  • Accept-Language / Content-Language
    The former is not applicable, the latter can be implemented but it's a guessing game.
  • Accept-Ranges / Range / Content-Range
    Implemented, with deviations from standard. Responses with multipart/byteranges are absurd to implement here.
  • Authorization
    Theoretically speaking, this can be used to access files that don't belong to current user. Feasible as is, but how to avoid horrid security implications?
  • Cache-Control
    Not really applicable. Caching local files should be done by OS.
  • Connection / Keep-Alive
    For some methods, it's somewhat possible to implement aborting with TimeoutError and closing file descriptors if the response body state happens to be stalling. Fun, but not very useful and probably not very robust.
  • Expect / request Content-Length
    This can be applicable as in "is there enough of free space on device" or "does FS support files this big". Unfortunately, we don't always know request body size, free space can vary, and 100 is not the most convenient thing in HTTP.
  • Cookie / Set-Cookie
    Maybe there will be a brilliant idea. Someday.
  • Host / Origin / Referer
    Maybe there should be some value that will be ignored internally anyway.
  • If-Match / If-None-Match / ETag
    Implemented.
  • If-Modified-Since / If-Unmodified-Since / Last-Modified
    Implemented.
  • Client Hints
    There are lots of interesting things like Downlink, but usability is questionable even if it was simple to implement.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.