sergi/jsftp — pull request #31 by sergi (2012-11-20 13:38:27+00:00)
Title: Implement proper streaming for passive commands and add tests

This fix gives proper Nodejs streaming capabilities to FTP. Until now, jsftp relied on buffering, although it had streaming methods ready to be used (`getPutSocket` and `getGetSocket`). However, upon some testing with vfs-ftp I found out that piping wouldn't work, and it would never do because of the way that PASV commands were handled at the moment. That is, sequentially.

Passive command handling methods have been now split into two, `getPasvSocket` and `orderedPasv`. The latter uses the former, and now the user of the API can choose what API to use (the streaming API is less straightforward). In this way, `getPutSocket` and `getGetSocket` can directly use the methods that allow them to do multiple requests and deal with the returned sockets (streams). The implementation is cleaner now.

In case you were wondering why not get rid of the sequential API, it is because the sequential API is useful for when the user wants to ensure that an FTP command will always be executed after another, but still write it in procedural style (not callback-style). That was needed for the way jsDAV calles different fs functions, which necessarily doesn't compose them and behave independently. Check out the test "test multiple concurrent pasvs" as an example.

**A bit more (and a bit duplicated) information**
This is a big rehaul of how streaming passive requests are handled.

Improved:
- Before, streams were not properly resumed and paused. Resulting on timeouts in piping streams, for example.
- Split passive function into two. `getPasvSocket` and `orderedPasv`. The former retrieves the passive socket and the latter is for PASV calls that have to be synchronous, like in

```
ftp.put("file1", callback1);
ftp.put("file2", callback2);
...
```
- VFS will be using only streaming functions, of course.
- The PASV call now goes through the normal flow that includes initialisation, auth, etc. Before a PASV call on connecting to the Ftp would fail because auth didn't happen first.
- Other small but important changes.

The diff should be pretty self-explanatory and I of course added new unit tests for the changes.