Skip to content

Commit 2609778

Browse files
committed
Determ build
1 parent de1149c commit 2609778

7 files changed

Lines changed: 542 additions & 356 deletions

File tree

CSharpFITS/CSharpFITS.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
<LangVersion>9.0</LangVersion>
1212
<PackageReadmeFile>README.md</PackageReadmeFile>
1313
<PackageLicenseFile>license.txt</PackageLicenseFile>
14-
<AssemblyVersion>2.1.8.2</AssemblyVersion>
15-
<FileVersion>2.1.8.2</FileVersion>
14+
<AssemblyVersion>3.1.8.2</AssemblyVersion>
15+
<FileVersion>3.1.8.2</FileVersion>
1616
<PackageTags>Astronomy,FITS,Image</PackageTags>
1717
<RepositoryUrl>https://github.com/SharpAstro/FITS.Lib</RepositoryUrl>
1818
<PackageProjectUrl>https://github.com/SharpAstro/FITS.Lib</PackageProjectUrl>
1919
<Description>Supports reading and writing FITS files</Description>
20-
<Version>2.1.8</Version>
20+
<Version>3.1.8</Version>
2121
<Authors>Virtual Observatory - India</Authors>
2222
<PackageId>FITS.Lib</PackageId>
2323
<RootNamespace>nom.tam</RootNamespace>

CSharpFITS/image/ImageTiler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ protected internal virtual void FillFileData(Array output, int delta, int output
279279
{
280280
f.Seek(fileOffset + delta, SeekOrigin.Begin);
281281

282+
// CA2022: Underlying ArrayDataIO.Read uses exact read logic (see BufferedDataStream.ReadBytesExactly)
282283
if (base_Renamed == typeof(float))
283284
{
284285
f.Read((float[])output, outputOffset, segment);

CSharpFITS/packages.lock.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"version": 1,
3+
"dependencies": {
4+
".NETStandard,Version=v2.0": {
5+
"NETStandard.Library": {
6+
"type": "Direct",
7+
"requested": "[2.0.3, )",
8+
"resolved": "2.0.3",
9+
"contentHash": "st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
10+
"dependencies": {
11+
"Microsoft.NETCore.Platforms": "1.1.0"
12+
}
13+
},
14+
"Microsoft.NETCore.Platforms": {
15+
"type": "Transitive",
16+
"resolved": "1.1.0",
17+
"contentHash": "kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A=="
18+
}
19+
},
20+
"net10.0": {}
21+
}
22+
}

CSharpFITS/util/BufferedDataStream.cs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public override int Read(byte[] buf, int offset, int size)
296296

297297
try
298298
{
299-
byte[] tbuf = _in.ReadBytes(size);
299+
byte[] tbuf = ReadBytesExactly(size);
300300
Buffer.BlockCopy(tbuf, 0, buf, offset, tbuf.Length);
301301
result = tbuf.Length;
302302
}
@@ -314,7 +314,7 @@ public override int Read(sbyte[] buf, int offset, int size)
314314

315315
try
316316
{
317-
byte[] tbuf = _in.ReadBytes(size);
317+
byte[] tbuf = ReadBytesExactly(size);
318318
for (int i = 0; i < tbuf.Length; ++i)
319319
{
320320
buf[i + offset] = (sbyte)tbuf[i];
@@ -326,7 +326,7 @@ public override int Read(sbyte[] buf, int offset, int size)
326326
result = 0;
327327
}
328328

329-
return 0;
329+
return result;
330330
}
331331

332332
public override int Read(bool[] buf, int offset, int size)
@@ -335,7 +335,7 @@ public override int Read(bool[] buf, int offset, int size)
335335

336336
try
337337
{
338-
byte[] tbuf = _in.ReadBytes(boolByteStride * size);
338+
byte[] tbuf = ReadBytesExactly(boolByteStride * size);
339339
for (int b = 0; b < tbuf.Length; ++nRead, b += boolByteStride)
340340
{
341341
buf[nRead + offset] = BitConverter.ToBoolean(tbuf, b);
@@ -358,7 +358,7 @@ public override int Read(char[] buf, int offset, int size)
358358

359359
try
360360
{
361-
byte[] tbuf = _in.ReadBytes(charByteStride * size);
361+
byte[] tbuf = ReadBytesExactly(charByteStride * size);
362362
for (int b = 0; b < tbuf.Length; ++nRead, b += charByteStride)
363363
{
364364
buf[nRead + offset] = (char)((tbuf[b] << 8) | tbuf[b + 1]);
@@ -378,7 +378,7 @@ public override int Read(short[] buf, int offset, int size)
378378

379379
try
380380
{
381-
byte[] tbuf = _in.ReadBytes(shortByteStride * size);
381+
byte[] tbuf = ReadBytesExactly(shortByteStride * size);
382382
#if NETSTANDARD2_0
383383
for (int b = 0; b < tbuf.Length; ++nRead, b += shortByteStride)
384384
{
@@ -405,7 +405,7 @@ public override int Read(int[] buf, int offset, int size)
405405

406406
try
407407
{
408-
byte[] tbuf = _in.ReadBytes(intByteStride * size);
408+
byte[] tbuf = ReadBytesExactly(intByteStride * size);
409409
#if NETSTANDARD2_0
410410
for (int b = 0; b < tbuf.Length; ++nRead, b += intByteStride)
411411
{
@@ -432,7 +432,7 @@ public override int Read(long[] buf, int offset, int size)
432432

433433
try
434434
{
435-
byte[] tbuf = _in.ReadBytes(longByteStride * size);
435+
byte[] tbuf = ReadBytesExactly(longByteStride * size);
436436
#if NETSTANDARD2_0
437437
for (int b = 0; b < tbuf.Length; ++nRead, b += longByteStride)
438438
{
@@ -460,7 +460,7 @@ public override int Read(float[] buf, int offset, int size)
460460

461461
try
462462
{
463-
byte[] tbuf = _in.ReadBytes(floatByteStride * size);
463+
byte[] tbuf = ReadBytesExactly(floatByteStride * size);
464464
#if NETSTANDARD2_0
465465
for (int b = 0; b < tbuf.Length; ++nRead, b += floatByteStride)
466466
{
@@ -488,7 +488,7 @@ public override int Read(double[] buf, int offset, int size)
488488

489489
try
490490
{
491-
byte[] tbuf = _in.ReadBytes(doubleByteStride * size);
491+
byte[] tbuf = ReadBytesExactly(doubleByteStride * size);
492492
#if NETSTANDARD2_0
493493
for (int b = 0; b < tbuf.Length; ++nRead, b += doubleByteStride)
494494
{
@@ -1049,5 +1049,33 @@ public override void Close()
10491049
protected byte[] _garbageBuf;
10501050
protected int primitiveArrayCount;
10511051
#endregion
1052+
1053+
#region Helper Methods
1054+
/// <summary>
1055+
/// Reads exactly the specified number of bytes from the underlying stream.
1056+
/// Throws EndOfStreamException if fewer bytes are available.
1057+
/// </summary>
1058+
/// <param name="count">The number of bytes to read.</param>
1059+
/// <returns>A byte array containing exactly count bytes.</returns>
1060+
private byte[] ReadBytesExactly(int count)
1061+
{
1062+
byte[] buffer = new byte[count];
1063+
#if NETSTANDARD2_0
1064+
int totalRead = 0;
1065+
while (totalRead < count)
1066+
{
1067+
int bytesRead = _s.Read(buffer, totalRead, count - totalRead);
1068+
if (bytesRead == 0)
1069+
{
1070+
throw new EndOfStreamException($"Unable to read {count} bytes from stream. Only {totalRead} bytes were available.");
1071+
}
1072+
totalRead += bytesRead;
1073+
}
1074+
#else
1075+
_s.ReadExactly(buffer);
1076+
#endif
1077+
return buffer;
1078+
}
1079+
#endregion
10521080
}
10531081
}

0 commit comments

Comments
 (0)