Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

[discussion] library choice changes -- requests, vinyl #97

@dignifiedquire

Description

@dignifiedquire

As some might have seen or read I'm currently suggesting to move away from using raw http.request and if possible to drop the code in src/get-files-stream.js, which is mostly using vinyl to generate a nested multipart requests of the files to be uploaded to the API. But as @jbenet pointed out on IRC I have not properly explained why I make these suggestions and why I think doing so would be very beneficial for this module.

To understand my reasoning let me formulate the main goals for this project as I understand them:

  1. Provide a small and simple wrapper around the http API of ipfs daemon
  2. 100% compatibility between node and browser
  3. Do not reinvent/reimplement the wheel, unless there is a very good reason to do so

Part 1: Drop direct usage of http.request

A lot of the code in this project is reimplementing things that already have been implemented and battle tested in other modules, when it comes to the usage of http.request. Two main projects come here to mind request and superagent. As explored in #92 the only request module that will do everything we need and has excellent support for node and browser seems to be request. The initial reason for exploring these options for me was #69 which has strong implications for the stability of station.

Part 2: Drop vinyl if possible

First vinyl on its own is a representation of the file system in memory and a nice API around it to access it. This taken on itself is nothing bad in any way, but does not need to be in this module in my opinion as it adds additional bloat which in the browser has very little relevance, as the power of vinyl comes from it being able to actually access the file system in the background to read it in.

we'll still need something like it (a js object to represent a file before reading it all in).
@jbenet (IRC)

From my understanding, we do not need a representation of a file object in this API wrapper. Application code around this API might very well need it, but for the purposes of uploading files via the http API there are more straight forward ways to do it:

  1. [browser][node]: The content of a file and the filename are passed: We can directly generate a multipart request from this.
  2. [node]: The path to a file is passed: Use fs.createReadStream to read the file from the file system and generate the multipart stream
  3. [node]: The path of a directory is passed: Use something like glob to walk the directory and convert into the same structure as 2.
  4. [browser]: The content of a directory of files is passed: Use the conversion from 3. to generate the multipart request.

I hope this explanation makes my thinking and efforts more understandable and sorry again for not writing this up earlier but parts of this were simply only understood by me when doing the research and work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions