Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

36 wiersze
941 B

  1. import {createWriteStream} from "fs"
  2. function handleEpipe(error) {
  3. if (error.code === "EPIPE" || error.errno === "EPIPE") {
  4. process.exit(0);
  5. }
  6. }
  7. export default function(file) {
  8. var output = (file === "-" ? process.stdout : createWriteStream(file)).on("error", handleEpipe),
  9. queue = Promise.resolve();
  10. return {
  11. write: function(data) {
  12. return queue = queue.then(function() {
  13. return new Promise(function(resolve, reject) {
  14. output.write(data, function(error) {
  15. if (error) reject(error);
  16. else resolve();
  17. });
  18. });
  19. });
  20. },
  21. end: function() {
  22. if (output === process.stdout) return queue;
  23. return queue = queue.then(function() {
  24. return new Promise(function(resolve, reject) {
  25. output.end(function(error) {
  26. if (error) reject(error);
  27. else resolve();
  28. });
  29. });
  30. });
  31. }
  32. };
  33. }