github.com/iDigitalFlame/xmt@v0.5.4/data/c_fs.go (about)

     1  //go:build go1.16
     2  // +build go1.16
     3  
     4  // Copyright (C) 2020 - 2023 iDigitalFlame
     5  //
     6  // This program is free software: you can redistribute it and/or modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // any later version.
    10  //
    11  // This program is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    18  
    19  package data
    20  
    21  import (
    22  	"io/fs"
    23  	"os"
    24  )
    25  
    26  // A DirEntry is an entry read from a directory
    27  // (using the ReadDir function or a ReadDirFile's ReadDir method).
    28  //
    29  // Alias of "fs.DirEntry".
    30  //
    31  // This is a pre go1.16 compatibility helper.
    32  type DirEntry = fs.DirEntry
    33  
    34  // ReadDir reads the named directory, returning all its directory entries sorted
    35  // by filename. If an error occurs reading the directory, ReadDir returns the
    36  // entries it was able to read before the error, along with the error.
    37  //
    38  // Alias of "os.ReadDir".
    39  //
    40  // This is a pre go1.16 compatibility helper.
    41  func ReadDir(n string) ([]DirEntry, error) {
    42  	return os.ReadDir(n)
    43  }
    44  
    45  // CreateTemp creates a new temporary file in the directory dir, opens the file
    46  // for reading and writing, and returns the resulting file.
    47  //
    48  // The filename is generated by taking pattern and adding a random string to the
    49  // end.
    50  //
    51  // If pattern includes a "*", the random string replaces the last "*".
    52  //
    53  // If dir is the empty string, CreateTemp uses the default directory for temporary
    54  // files, as returned by TempDir.
    55  //
    56  // Multiple programs or goroutines calling CreateTemp simultaneously will not choose
    57  // the same file.
    58  //
    59  // The caller can use the file's Name method to find the pathname of the file.
    60  // It is the caller's responsibility to remove the file when it is no longer needed.
    61  //
    62  // Alias of "os.CreateTemp".
    63  //
    64  // This is a pre go1.16 compatibility helper.
    65  func CreateTemp(d, p string) (*os.File, error) {
    66  	return os.CreateTemp(d, p)
    67  }