Giter Site home page Giter Site logo

dirtreehash's Introduction

## 小工具需求说明
1. 对整个目录下的所有文件进行遍历,获取所有文件的大小和计算文件的sha1哈希值,记录在一个文件里面,并保存在hashResult目录下
2. 结果文件格式:每一行一个文件,用逗号隔开,前面是文件名称,后面是哈希值,文件大小
3. 可以在目录中增加.sha1Ignore文件,将需要忽略的文件加入,【**目前尚未支持通配符**】

dirtreehash's People

Contributors

cooladdr avatar

Watchers

 avatar  avatar

dirtreehash's Issues

对golang标准库的不熟悉

描述

对于某些实现,在标准库中,已经内置了相应的方法,不用自己再去实现

func walkDir(dir string, wait *sync.WaitGroup, hashStr chan<- string) {
    defer wait.Done()

    ignores := getIgnoreFiles(dir)
    for _, entry := range dirents(dir) {
        //忽略文件
        name := entry.Name()
        if ignores != nil && ignores[name] {
            continue
        }

        if entry.IsDir() {
            wait.Add(1)
            subdir := filepath.Join(dir, name)
            go walkDir(subdir, wait, hashStr)
        } else {
            fileFullName := filepath.Join(dir, name)
            fileSize := entry.Size()
            fileHash := getHash(fileFullName)
            hashStr <- fmt.Sprintf("%s, %v, %d\n", fileFullName, fileHash, fileSize)
        }
    }
}

大文件处理

描述

未进行大文件处理

func getHash(file string) []byte {
    f, err := os.Open(file)
    if err != nil {
        fmt.Printf("Open:%s error", file)
        panic(err)
    }
    defer f.Close()

    h := sha1.New()
    _, err = io.Copy(h, f)
    if err != nil {
        panic(err)
    }

    return h.Sum(nil)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.