• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Go简易分布式对象存储 合并文件的所有分块为一个文件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

项目

项目地址: https://github.com/Draymonders/cloud
欢迎大家Watch or Star

缘由

由于项目中对大文件进行5MB为一个分块上传(多线程,提升上传效率),因此所有分块上传完是要求合并的。

filepath: 分块所在目录,分块按照数字标号来有序存储
filestore: 生成一个新文件的目录位置

脚本文件

#!/bin/bash

filepath=$1
filestore=$2

echo "filepath: " $filepath
echo "filestorepath: "  $filestore

if [ ! -f $filestore ]; then
        echo "$filestore not exist"
else
        rm -f $filestore
fi

for item in `ls $filepath | sort -n`
do
        `cat $filepath/${item} >> ${filestore}`
        echo "merge ${filepath/${item}}  to $filestore ok"
done

echo "file store ok"

Go进行脚本控制

package main

import (
	"fmt"
	"os"
	"os/exec"
)

const (
	// dirPath     = "/data/tmp/"
	dirPath = "d:\\tmp\\"
)

func main() {
	var cmd *exec.Cmd
	filepath := dirPath + "/root5d0dd1ec/"
	filestore := dirPath + "1111111.pdf"

	cmd = exec.Command(dirPath+"mergeAll.sh", filepath, filestore)
	// cmd.Run()
	if _, err := cmd.Output(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	} else {
		fmt.Println(filestore, " has been merge complete")
	}
}

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap