Using MTP on macOS with Node.js
Media Transfer Protocol (MTP) has replaced USB Mass Storage as the dominant protocol for transferring digital media between an Android phone and a computer. USB Mass Storage allows devices to be mounted as drives on the host computer, and while MTP also allows drives to be mounted, it happens at a level where it's easier to restrict which files are made available to the host system. If that sounds to you like something Microsoft would design, you'd be right.
MTP works great on Windows machines of course, and surprisingly well on Linux. However, while there's apparently some basic MTP support on macOS, it doesn't even allow you to mount a device without external software, like Android File Transfer.
I spent some time today looking at options for connecting to an Android phone on macOS with MTP using Node.js. Here are some possible options:
- Use FUSE (Filesystem in Userspace) with Node bindings. This will requires installation of FUSE for macOS first, which I think also involves installing a kernel extension. So it's basically a no-go for macOS High Sierra and above.
- Write a wrapper for libmtp, using this unmaintained repo as a base.
- Port parts of this application over to Node.js, as its only dependency seems to be libusb. This means essentially writing your own MTP implementation on top of node-usb.
Since MTP has been standardised as part of the USB Device Class specifications, writing an MTP implementation on node-usb does make sense, but will probably be a lot of work. I think I will opt for (2) first as it's easier, with (3) as a fallback.