详细内容
当前位置 首页 >> 技术文档 >> NodeJS >> 正文
nodejs直接导出文本文件
发布日期:2024-06-04     点击:59     字体:[ ]

const str=`今天天气不错,挺风和日丽的。`;


  const downloadOptions = {

    'Content-Disposition': `attachment; filename*=UTF-8''str.txt`,

    'Content-Type': 'text/plain',

  };


  const bufferStream = new Stream.PassThrough();

  bufferStream.end(Buffer.from(str, 'utf8'));

  bufferStream.pipe(response).writeHead(200, downloadOptions);


这里的response可以是express的response


用户评论
昵称 
内容  *
验证码   
   
Copyright © 2010 zdbase.com All Rights Reserved. 苏ICP备15039389号 可人软件设计