You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

  1. var common = require('../common');
  2. var formidable = common.formidable;
  3. var http = require('http');
  4. var fs = require('fs');
  5. var path = require('path');
  6. var hashish = require('hashish');
  7. var assert = require('assert');
  8. var testFilePath = path.join(__dirname, '../fixture/file/binaryfile.tar.gz');
  9. var server = http.createServer(function(req, res) {
  10. var form = new formidable.IncomingForm();
  11. form.parse(req, function(err, fields, files) {
  12. assert.equal(hashish(files).length, 1);
  13. var file = files.file;
  14. assert.equal(file.size, 301);
  15. var uploaded = fs.readFileSync(file.path);
  16. var original = fs.readFileSync(testFilePath);
  17. assert.deepEqual(uploaded, original);
  18. res.end();
  19. server.close();
  20. });
  21. });
  22. var port = common.port;
  23. server.listen(port, function(err){
  24. assert.equal(err, null);
  25. var request = http.request({
  26. port: port,
  27. method: 'POST',
  28. headers: {
  29. 'Content-Type': 'application/octet-stream'
  30. }
  31. });
  32. fs.createReadStream(testFilePath).pipe(request);
  33. });