Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

README.md 1.8 KiB

há 3 anos
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # stream-throttle #
  2. A rate limiter for Node.js streams.
  3. ## API usage
  4. This module exports two classes, `Throttle` and `ThrottleGroup`.
  5. `Throttle` creates a single throttled stream, based on `stream.Transform`. It accepts an `opts` parameter with the following keys:
  6. * `opts.rate` is the throttling rate, in bytes per second.
  7. * `opts.chunksize` (optional) is the maximum chunk size into which larger writes are decomposed; the default is `opts.rate`/10.
  8. The `opts` object may also contain options to be passed to the `stream.Transform` constructor.
  9. For example, the following code throttles stdin to stdout at 10 bytes per second:
  10. process.stdin.pipe(new Throttle({rate: 10})).pipe(process.stdout)
  11. `ThrottleGroup` allows the creation of a group of streams whose aggregate bandwidth is throttled. The constructor accepts the same `opts` argument as for `Throttle`. Call `throttle` on a `ThrottleGroup` object to create a new throttled stream belonging to the group.
  12. For example, the following code creates two HTTP connections to `www.google.com:80`, and throttles their aggregate (downstream) bandwidth to 10 KB/s:
  13. var addr = { host: 'www.google.com', port: 80 };
  14. var tg = new ThrottleGroup({rate: 10240});
  15. var conn1 = net.createConnection(addr),
  16. conn2 = net.createConnection(addr);
  17. var thr1 = conn1.pipe(tg.throttle()),
  18. thr2 = conn2.pipe(tg.throttle());
  19. // Reads from thr1 and thr2 are throttled to 10 KB/s in aggregate
  20. ## Command line usage
  21. This package installs a `throttleproxy` binary which implements a command-line utility for throttling connections. Run `throttleproxy -h` for instructions.
  22. ## Contributing
  23. Feel free to open an issue or send a pull request.
  24. ## License
  25. BSD-style. See the LICENSE file.
  26. ## Author
  27. Copyright © 2013 Tiago Quelhas. Contact me at `<tiagoq@gmail.com>`.