/// <summary> /// Sets an attribute for a file. If it already exists, it will be replaced. /// </summary> /// <param name="this">The <see cref="FileInfo"/> referring to the file.</param> /// <param name="name">The name of the attribute to set.</param> /// <param name="data">The attribute data to write.</param> /// <exception cref="FileNotFoundException">If the file <paramref name="this"/> does not exist.</exception> /// <exception cref="ArgumentException"> /// If <paramref name="data"/> is larger than <see cref="Tsuku.MAX_ATTR_SIZE"/> bytes, or if /// <paramref name="name"/> is longer than <see cref="Tsuku.MAX_NAME_LEN"/>. /// </exception> /// <exception cref="PlatformNotSupportedException"> /// If the filesystem of the file <paramref name="this"/> does not support extended attributes on the /// current operating system. /// </exception> public static void SetAttribute(this FileInfo @this, string name, ReadOnlySpan <byte> data) { DataAssertions.CheckValidity(name, data); if ([email protected]) { throw new FileNotFoundException("The requested file does not exist."); } Tsuku.GetImplementation(@this).Write(@this, name, data); }
/// <summary> /// Gets an attribute from a file. /// </summary> /// <param name="this">The <see cref="FileInfo"/> referring to the file.</param> /// <param name="name">The name of the attribute to get.</param> /// <exception cref="FileNotFoundException">If the file <paramref name="this"/>, or attribute does not exist.</exception> /// <exception cref="ArgumentException"> /// If <paramref name="name"/> is longer than <see cref="Tsuku.MAX_NAME_LEN"/>. /// </exception> /// <exception cref="PlatformNotSupportedException"> /// If the filesystem of the file <paramref name="this"/> does not support extended attributes on the /// current operating system. /// </exception> public static byte[] GetAttribute(this FileInfo @this, string name) { Span <byte> data = stackalloc byte[Tsuku.MAX_ATTR_SIZE]; data.Clear(); DataAssertions.CheckValidity(name, data); int readBytes = Tsuku.GetImplementation(@this) .Read(@this, name, ref data); byte[] buf = new byte[readBytes]; data[..readBytes].CopyTo(buf);