// 输出文件。 // name指定文件名,为空时默认保持原文件名不变。 func (self *Context) FileOutput(name ...string) { // 读取完整文件流 bytes, err := ioutil.ReadAll(self.Response.Body) self.Response.Body.Close() if err != nil { panic(err.Error()) return } // 智能设置完整文件名 _, s := path.Split(self.GetUrl()) n := strings.Split(s, "?")[0] baseName := strings.Split(n, ".")[0] var ext string if len(name) > 0 { p, n := path.Split(name[0]) if baseName2 := strings.Split(n, ".")[0]; baseName2 != "" { baseName = p + baseName2 } ext = path.Ext(n) } if ext == "" { ext = path.Ext(n) } if ext == "" { ext = ".html" } // 保存到文件临时队列 self.Lock() self.files = append(self.files, data.GetFileCell(self.GetRuleName(), baseName+ext, bytes)) self.Unlock() }
// 输出文件。 // name指定文件名,为空时默认保持原文件名不变。 func (self *Context) FileOutput(name ...string) { _, s := path.Split(self.GetUrl()) n := strings.Split(s, "?")[0] // 初始化 baseName := strings.Split(n, ".")[0] ext := path.Ext(n) if len(name) > 0 { p, n := path.Split(name[0]) if baseName2 := strings.Split(n, ".")[0]; baseName2 != "" { baseName = p + baseName2 } if ext == "" { ext = path.Ext(n) } } if ext == "" { ext = ".html" } self.Lock() self.files = append(self.files, data.GetFileCell(self.GetRuleName(), baseName+ext, self.Response.Body)) self.Unlock() }