index.js 723 B

123456789101112131415161718192021222324252627
  1. /**
  2. * node-compress-commons
  3. *
  4. * Copyright (c) 2014 Chris Talkington, contributors.
  5. * Licensed under the MIT license.
  6. * https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT
  7. */
  8. var Stream = require('stream').Stream;
  9. var PassThrough = require('readable-stream').PassThrough;
  10. var isStream = require('is-stream');
  11. var util = module.exports = {};
  12. util.normalizeInputSource = function(source) {
  13. if (source === null) {
  14. return Buffer.alloc(0);
  15. } else if (typeof source === 'string') {
  16. return Buffer.from(source);
  17. } else if (isStream(source) && !source._readableState) {
  18. var normalized = new PassThrough();
  19. source.pipe(normalized);
  20. return normalized;
  21. }
  22. return source;
  23. };